Skip to content

Commit 18689c2

Browse files
committed
[#690] Add missing documentation and fix clippy warnings
1 parent 62bf2f6 commit 18689c2

File tree

7 files changed

+88
-23
lines changed

7 files changed

+88
-23
lines changed

iceoryx2/src/port/client.rs

+74-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<
354354
data_segment,
355355
segment_states: {
356356
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);
358358
for _ in 0..max_number_of_segments {
359359
v.push(SegmentState::new(number_of_requests))
360360
}
@@ -690,6 +690,41 @@ impl<
690690
ResponseHeader: Debug + ZeroCopySend,
691691
> Client<Service, [RequestPayload], RequestHeader, ResponsePayload, ResponseHeader>
692692
{
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+
/// ```
693728
pub fn loan_slice(
694729
&self,
695730
slice_len: usize,
@@ -710,6 +745,42 @@ impl<
710745
ResponseHeader: Debug + ZeroCopySend,
711746
> Client<Service, [RequestPayload], RequestHeader, ResponsePayload, ResponseHeader>
712747
{
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
713784
pub fn loan_slice_uninit(
714785
&self,
715786
slice_len: usize,
@@ -727,6 +798,7 @@ impl<
727798
unsafe { self.loan_slice_uninit_impl(slice_len, slice_len) }
728799
}
729800

801+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
730802
unsafe fn loan_slice_uninit_impl(
731803
&self,
732804
slice_len: usize,
@@ -817,6 +889,7 @@ impl<
817889
> Client<Service, [CustomPayloadMarker], RequestHeader, ResponsePayload, ResponseHeader>
818890
{
819891
#[doc(hidden)]
892+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
820893
pub unsafe fn loan_custom_payload(
821894
&self,
822895
slice_len: usize,

iceoryx2/src/port/server.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<
283283
let response_sender = Sender {
284284
segment_states: {
285285
let mut v =
286-
std::vec::Vec::<SegmentState>::with_capacity(max_number_of_segments as usize);
286+
alloc::vec::Vec::<SegmentState>::with_capacity(max_number_of_segments as usize);
287287
for _ in 0..max_number_of_segments {
288288
v.push(SegmentState::new(number_of_responses))
289289
}
@@ -570,6 +570,7 @@ impl<
570570
/// # Ok(())
571571
/// # }
572572
/// ```
573+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
573574
pub fn receive(
574575
&self,
575576
) -> Result<
@@ -624,6 +625,7 @@ impl<
624625
> Server<Service, [CustomPayloadMarker], RequestHeader, ResponsePayload, ResponseHeader>
625626
{
626627
#[doc(hidden)]
628+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
627629
pub unsafe fn receive_custom_payload(
628630
&self,
629631
) -> Result<

iceoryx2/src/service/builder/request_response.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ impl<
12151215

12161216
/// If the [`Service`] exists, it will be opened otherwise a new [`Service`] will be
12171217
/// created.
1218+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
12181219
pub fn open_or_create(
12191220
self,
12201221
) -> Result<
@@ -1236,6 +1237,7 @@ impl<
12361237
/// If the [`Service`] already exists all attribute requirements must be satisfied,
12371238
/// and service payload type must be the same, otherwise the open process will fail.
12381239
/// If the [`Service`] does not exist the required attributes will be defined in the [`Service`].
1240+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
12391241
pub fn open_or_create_with_attributes(
12401242
mut self,
12411243
required_attributes: &AttributeVerifier,
@@ -1254,6 +1256,7 @@ impl<
12541256
}
12551257

12561258
/// Opens an existing [`Service`].
1259+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
12571260
pub fn open(
12581261
self,
12591262
) -> Result<
@@ -1271,6 +1274,7 @@ impl<
12711274

12721275
/// Opens an existing [`Service`] with attribute requirements. If the defined attribute
12731276
/// requirements are not satisfied the open process will fail.
1277+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
12741278
pub fn open_with_attributes(
12751279
mut self,
12761280
required_attributes: &AttributeVerifier,
@@ -1289,6 +1293,7 @@ impl<
12891293
}
12901294

12911295
/// Creates a new [`Service`].
1296+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
12921297
pub fn create(
12931298
self,
12941299
) -> Result<
@@ -1305,6 +1310,7 @@ impl<
13051310
}
13061311

13071312
/// Creates a new [`Service`] with a set of attributes.
1313+
#[allow(clippy::type_complexity)] // type alias would require 5 generic parameters which hardly reduces complexity
13081314
pub fn create_with_attributes(
13091315
mut self,
13101316
attributes: &AttributeSpecifier,

iceoryx2/src/service/header/publish_subscribe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Header {
6060
/// Returns how many elements are stored inside the sample's payload.
6161
///
6262
/// # Details when using
63-
/// [`CustomPayloadMarker`](crate::service::builder::publish_subscribe::CustomPayloadMarker)
63+
/// [`CustomPayloadMarker`](crate::service::builder::CustomPayloadMarker)
6464
///
6565
/// In this case the number of elements relates to the element defined in the
6666
/// [`MessageTypeDetails`](crate::service::static_config::message_type_details::MessageTypeDetails).

iceoryx2/src/service/header/request_response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl RequestHeader {
3636
/// Returns how many elements are stored inside the requests's payload.
3737
///
3838
/// # Details when using
39-
/// [`CustomPayloadMarker`](crate::service::builder::publish_subscribe::CustomPayloadMarker)
39+
/// [`CustomPayloadMarker`](crate::service::builder::CustomPayloadMarker)
4040
///
4141
/// In this case the number of elements relates to the element defined in the
4242
/// [`MessageTypeDetails`](crate::service::static_config::message_type_details::MessageTypeDetails).
@@ -67,7 +67,7 @@ impl ResponseHeader {
6767
/// Returns how many elements are stored inside the response's payload.
6868
///
6969
/// # Details when using
70-
/// [`CustomPayloadMarker`](crate::service::builder::publish_subscribe::CustomPayloadMarker)
70+
/// [`CustomPayloadMarker`](crate::service::builder::CustomPayloadMarker)
7171
///
7272
/// In this case the number of elements relates to the element defined in the
7373
/// [`MessageTypeDetails`](crate::service::static_config::message_type_details::MessageTypeDetails).

iceoryx2/src/service/port_factory/client.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,13 @@ impl<
198198
}
199199

200200
impl<
201-
'factory,
202201
Service: service::Service,
203202
RequestPayload: Debug + ZeroCopySend,
204203
RequestHeader: Debug + ZeroCopySend,
205204
ResponsePayload: Debug + ZeroCopySend + ?Sized,
206205
ResponseHeader: Debug + ZeroCopySend,
207206
>
208-
PortFactoryClient<
209-
'factory,
210-
Service,
211-
[RequestPayload],
212-
RequestHeader,
213-
ResponsePayload,
214-
ResponseHeader,
215-
>
207+
PortFactoryClient<'_, Service, [RequestPayload], RequestHeader, ResponsePayload, ResponseHeader>
216208
{
217209
/// Sets the maximum slice length that a user can allocate with
218210
/// [`Client::loan_slice()`] or [`Client::loan_slice_uninit()`].

iceoryx2/src/service/port_factory/server.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,13 @@ impl<
212212
}
213213

214214
impl<
215-
'factory,
216215
Service: service::Service,
217216
RequestPayload: Debug + ZeroCopySend + ?Sized,
218217
RequestHeader: Debug + ZeroCopySend,
219218
ResponsePayload: Debug + ZeroCopySend,
220219
ResponseHeader: Debug + ZeroCopySend,
221220
>
222-
PortFactoryServer<
223-
'factory,
224-
Service,
225-
RequestPayload,
226-
RequestHeader,
227-
[ResponsePayload],
228-
ResponseHeader,
229-
>
221+
PortFactoryServer<'_, Service, RequestPayload, RequestHeader, [ResponsePayload], ResponseHeader>
230222
{
231223
/// Sets the maximum slice length that a user can allocate with
232224
/// [`ActiveRequest::loan_slice()`](crate::active_request::ActiveRequest::loan_slice()) or

0 commit comments

Comments
 (0)