Skip to content

Commit dccfa2a

Browse files
committed
[eclipse-iceoryx#4] Add documentation for container crate
1 parent eda1112 commit dccfa2a

File tree

4 files changed

+89
-15
lines changed

4 files changed

+89
-15
lines changed

iceoryx2-bb/container/src/byte_string.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
//! Relocatable (inter-process shared memory compatible) string implementations.
1414
//!
15-
//! The [`FixedSizeByteString`] has a fixed capacity defined at compile time.
15+
//! The [`FixedSizeByteString`](crate::byte_string::FixedSizeByteString) has a fixed capacity defined at compile time.
1616
//!
1717
//! # Example
1818
//!
@@ -80,7 +80,6 @@ pub struct FixedSizeByteString<const CAPACITY: usize> {
8080
}
8181

8282
unsafe impl<const CAPACITY: usize> Send for FixedSizeByteString<CAPACITY> {}
83-
unsafe impl<const CAPACITY: usize> Sync for FixedSizeByteString<CAPACITY> {}
8483

8584
impl<const CAPACITY: usize, const CAPACITY_OTHER: usize>
8685
PartialOrd<FixedSizeByteString<CAPACITY_OTHER>> for FixedSizeByteString<CAPACITY>
@@ -191,6 +190,7 @@ impl<const CAPACITY: usize> Default for FixedSizeByteString<CAPACITY> {
191190
}
192191
}
193192

193+
// Adds escape characters to the string so that it can be used for console output.
194194
pub fn as_escaped_string(bytes: &[u8]) -> String {
195195
String::from_utf8(
196196
bytes
@@ -403,6 +403,7 @@ impl<const CAPACITY: usize> FixedSizeByteString<CAPACITY> {
403403
/// * The 'idx' must by less than [`FixedSizeByteString::len()`].
404404
/// * The 'bytes.len()' must be less or equal than [`FixedSizeByteString::capacity()`] -
405405
/// [`FixedSizeByteString::len()`]
406+
///
406407
pub unsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8]) {
407408
unsafe {
408409
std::ptr::copy(

iceoryx2-bb/container/src/lib.rs

+76-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,85 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0 OR MIT
1212

13-
//! Contains standard container which are compatible with an inter-process shared memory usage.
13+
//! # Iceoryx2 Building Blocks (BB) Container
14+
//!
15+
//! This is a support library for iceoryx2 which comes with containers that are
16+
//! compatible with shared memory and can be used to construct custom payload types for
17+
//! inter-process communication.
18+
//!
19+
//! Most containers come in 3 variations:
20+
//! 1. `FixedSize***`, compile-time fixed size version. The capacity must be known at compile
21+
//! time.
22+
//! 2. `Relocatable***`, run-time fixed size version that is shared memory compatible. The
23+
//! capacity must be known when the object is created. **This object is not movable!**
24+
//! 3. `***`, run-time fixed size version that is **not** shared memory compatible but can be
25+
//! moved.
26+
//!
27+
//! # Example
28+
//!
29+
//! ## 1. Compile-Time FixedSize Containers
30+
//!
31+
//! We create a struct consisting of compile-time fixed size containers that can be used for
32+
//! zero copy inter-process communication.
33+
//!
34+
//! ```
35+
//! use iceoryx2_bb_container::byte_string::*;
36+
//! use iceoryx2_bb_container::vec::*;
37+
//!
38+
//! const TEXT_CAPACITY: usize = 123;
39+
//! const DATA_CAPACITY: usize = 456;
40+
//!
41+
//! #[repr(C)]
42+
//! struct MyMessageType {
43+
//! some_text: FixedSizeByteString<TEXT_CAPACITY>,
44+
//! some_data: FixedSizeVec<u64, DATA_CAPACITY>,
45+
//! }
46+
//!
47+
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
48+
//! let my_message = MyMessageType {
49+
//! some_text: FixedSizeByteString::from_bytes(b"Hello World")?,
50+
//! some_data: FixedSizeVec::new(),
51+
//! };
52+
//! # Ok(())
53+
//! # }
54+
//! ```
55+
//!
56+
//! ## 2. Shared Memory Compatible Run-Time FixedSize Containers
57+
//!
58+
//! Despite that the containers are already implemented, iceoryx2 itself does not yet support
59+
//! run-time fixed size types. It is planned and will come.
60+
//!
61+
//! ## 3. Run-Time FixedSize Containers
62+
//!
63+
//! We create a struct consisting of run-time fixed size containers. This can be interesting when
64+
//! it shall be used in a safety-critical environment where everything must be pre-allocated to
65+
//! ensure that required memory is always available.
66+
//!
67+
//! ```
68+
//! use iceoryx2_bb_container::queue::*;
69+
//!
70+
//! const QUEUE_CAPACITY: usize = 123;
71+
//!
72+
//! #[repr(C)]
73+
//! struct MyType {
74+
//! some_queue: Queue<u64>,
75+
//! }
76+
//!
77+
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
78+
//! let my_thing = MyType {
79+
//! some_queue: Queue::new(QUEUE_CAPACITY),
80+
//! };
81+
//! # Ok(())
82+
//! # }
83+
//! ```
1484
85+
/// A byte string similar to [`std::string::String`] but it does not support UTF-8
1586
pub mod byte_string;
87+
/// A queue similar to [`std::collections::VecDeque`]
1688
pub mod queue;
89+
/// Extends the [ByteString](crate::byte_string) so that custom string types with a semantic
90+
/// ruleset on their content can be realized.
1791
#[macro_use]
1892
pub mod semantic_string;
93+
/// A vector similar to [`std::vec::Vec`]
1994
pub mod vec;

iceoryx2-bb/container/src/queue.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
//! Two relocatable (inter process shared memory compatible) queues.
1414
//!
15-
//! The [`Queue`] which has a
16-
//! fixed capacity defined at runtime and the [`FixedSizeQueue`] which has a fixed capacity at
17-
//! compile time.
15+
//! The [`Queue`](crate::queue::Queue) which has a
16+
//! fixed capacity defined at runtime and the [`FixedSizeQueue`](crate::queue::FixedSizeQueue)
17+
//! which has a fixed capacity at compile time.
1818
//!
1919
//! # Examples
2020
//!
21-
//! ## Create [`Queue`] inside constructs which provides memory
21+
//! ## Create [`Queue`](crate::queue::Queue) inside constructs which provides memory
2222
//!
2323
//! ```
2424
//! use iceoryx2_bb_container::queue::RelocatableQueue;
@@ -42,7 +42,7 @@
4242
//! }
4343
//! ```
4444
//!
45-
//! ## Create [`Queue`] with allocator
45+
//! ## Create [`Queue`](crate::queue::Queue) with allocator
4646
//!
4747
//! ```
4848
//! use iceoryx2_bb_container::queue::RelocatableQueue;

iceoryx2-bb/container/src/vec.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
//! Two relocatable (inter-process shared memory compatible) vector implementations.
1414
//!
1515
//!
16-
//! The [`Vec`] which has a
17-
//! fixed capacity defined at runtime and the [`FixedSizeVec`] which has a fixed capacity at
18-
//! compile time.
16+
//! The [`Vec`](crate::vec::Vec) which has a
17+
//! fixed capacity defined at runtime and the [`FixedSizeVec`](crate::vec::FixedSizeVec)
18+
//! which has a fixed capacity at compile time.
1919
//!
2020
//! # Examples
2121
//!
22-
//! ## Create [`Vec`] inside constructs which provides memory
22+
//! ## Create [`Vec`](crate::vec::Vec) inside constructs which provides memory
2323
//!
2424
//! ```
2525
//! use iceoryx2_bb_container::vec::Vec;
@@ -43,7 +43,7 @@
4343
//! }
4444
//! ```
4545
//!
46-
//! ## Create [`Vec`] with allocator
46+
//! ## Create [`Vec`](crate::vec::Vec) with allocator
4747
//!
4848
//! ```
4949
//! use iceoryx2_bb_container::vec::Vec;
@@ -88,7 +88,6 @@ pub struct Vec<T> {
8888
}
8989

9090
unsafe impl<T: Send> Send for Vec<T> {}
91-
unsafe impl<T: Sync> Sync for Vec<T> {}
9291

9392
impl<T> Drop for Vec<T> {
9493
fn drop(&mut self) {
@@ -367,7 +366,6 @@ impl<T: Clone, const CAPACITY: usize> Clone for FixedSizeVec<T, CAPACITY> {
367366
}
368367

369368
unsafe impl<T: Send, const CAPACITY: usize> Send for FixedSizeVec<T, CAPACITY> {}
370-
unsafe impl<T: Sync, const CAPACITY: usize> Sync for FixedSizeVec<T, CAPACITY> {}
371369

372370
impl<T, const CAPACITY: usize> FixedSizeVec<T, CAPACITY> {
373371
/// Creates a new vector.

0 commit comments

Comments
 (0)