@@ -354,7 +354,7 @@ impl<
354
354
data_segment,
355
355
segment_states : {
356
356
let mut v =
357
- std :: vec:: Vec :: < SegmentState > :: with_capacity ( max_number_of_segments as usize ) ;
357
+ alloc :: vec:: Vec :: < SegmentState > :: with_capacity ( max_number_of_segments as usize ) ;
358
358
for _ in 0 ..max_number_of_segments {
359
359
v. push ( SegmentState :: new ( number_of_requests) )
360
360
}
@@ -690,6 +690,41 @@ impl<
690
690
ResponseHeader : Debug + ZeroCopySend ,
691
691
> Client < Service , [ RequestPayload ] , RequestHeader , ResponsePayload , ResponseHeader >
692
692
{
693
+ /// Loans/allocates a [`RequestMut`] from the underlying data segment of the [`Client`]
694
+ /// and initializes all slice elements with the default value. This can be a performance hit
695
+ /// and [`Client::loan_slice_uninit()`] can be used to loan a slice of
696
+ /// [`core::mem::MaybeUninit<Payload>`].
697
+ ///
698
+ /// On failure it returns [`LoanError`] describing the failure.
699
+ ///
700
+ /// # Example
701
+ ///
702
+ /// ```
703
+ /// use iceoryx2::prelude::*;
704
+ ///
705
+ /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
706
+ /// # let node = NodeBuilder::new().create::<ipc::Service>()?;
707
+ /// #
708
+ /// let service = node
709
+ /// .service_builder(&"My/Funk/ServiceName".try_into()?)
710
+ /// .request_response::<[u64], u64>()
711
+ /// .open_or_create()?;
712
+ ///
713
+ /// let client = service.client_builder()
714
+ /// .initial_max_slice_len(32)
715
+ /// .create()?;
716
+ ///
717
+ /// let slice_length = 13;
718
+ /// let mut request = client.loan_slice(slice_length)?;
719
+ /// for element in request.payload_mut() {
720
+ /// element = 1234;
721
+ /// }
722
+ ///
723
+ /// let pending_response = request.send()?;
724
+ ///
725
+ /// # Ok(())
726
+ /// # }
727
+ /// ```
693
728
pub fn loan_slice (
694
729
& self ,
695
730
slice_len : usize ,
@@ -710,6 +745,42 @@ impl<
710
745
ResponseHeader : Debug + ZeroCopySend ,
711
746
> Client < Service , [ RequestPayload ] , RequestHeader , ResponsePayload , ResponseHeader >
712
747
{
748
+ /// Loans/allocates a [`RequestMutUninit`] from the underlying data segment of the [`Client`].
749
+ /// The user has to initialize the payload before it can be sent.
750
+ ///
751
+ /// On failure it returns [`LoanError`] describing the failure.
752
+ ///
753
+ /// # Example
754
+ ///
755
+ /// ```
756
+ /// use iceoryx2::prelude::*;
757
+ ///
758
+ /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
759
+ /// # let node = NodeBuilder::new().create::<ipc::Service>()?;
760
+ /// #
761
+ /// let service = node
762
+ /// .service_builder(&"My/Funk/ServiceName".try_into()?)
763
+ /// .request_response::<[u64], u64>()
764
+ /// .open_or_create()?;
765
+ ///
766
+ /// let client = service.client_builder()
767
+ /// .initial_max_slice_len(32)
768
+ /// .create()?;
769
+ ///
770
+ /// let slice_length = 13;
771
+ /// let mut request = client.loan_slice_uninit(slice_length)?;
772
+ /// for element in request.payload_mut() {
773
+ /// element.write(1234);
774
+ /// }
775
+ /// // we have written the payload, initialize the request
776
+ /// let request = unsafe { request.assume_init() };
777
+ ///
778
+ /// let pending_response = request.send()?;
779
+ ///
780
+ /// # Ok(())
781
+ /// # }
782
+ /// ```
783
+ #[ allow( clippy:: type_complexity) ] // type alias would require 5 generic parameters which hardly reduces complexity
713
784
pub fn loan_slice_uninit (
714
785
& self ,
715
786
slice_len : usize ,
@@ -727,6 +798,7 @@ impl<
727
798
unsafe { self . loan_slice_uninit_impl ( slice_len, slice_len) }
728
799
}
729
800
801
+ #[ allow( clippy:: type_complexity) ] // type alias would require 5 generic parameters which hardly reduces complexity
730
802
unsafe fn loan_slice_uninit_impl (
731
803
& self ,
732
804
slice_len : usize ,
@@ -817,6 +889,7 @@ impl<
817
889
> Client < Service , [ CustomPayloadMarker ] , RequestHeader , ResponsePayload , ResponseHeader >
818
890
{
819
891
#[ doc( hidden) ]
892
+ #[ allow( clippy:: type_complexity) ] // type alias would require 5 generic parameters which hardly reduces complexity
820
893
pub unsafe fn loan_custom_payload (
821
894
& self ,
822
895
slice_len : usize ,
0 commit comments