File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,27 @@ use crate::ImplicitClone;
7
7
///
8
8
/// This type is cheap to clone and thus implements [`ImplicitClone`]. It can be created based on a
9
9
/// `&'static [T]` or based on a reference counted slice (`T`).
10
+ ///
11
+ /// Since `IArray<T>` is an immutable data structure, direct modifications like adding or removing
12
+ /// elements are not possible. To make changes, you need to convert it into a `Vec<T>` using
13
+ /// `.to_vec()`, modify the vector, and then convert it back into an `IArray<T>` using
14
+ /// `IArray::from`. Here's an example demonstrating this approach:
15
+ ///
16
+ /// ```rust
17
+ /// # use implicit_clone::unsync::*;
18
+ /// let iarray = IArray::from(vec![1, 2, 3]);
19
+ ///
20
+ /// // Convert to Vec, modify it, then convert back to IArray
21
+ /// let mut vec = iarray.to_vec();
22
+ /// vec.push(4);
23
+ /// vec.retain(|&x| x != 2); // Remove the element `2`
24
+ /// let new_iarray = IArray::from(vec);
25
+ ///
26
+ /// assert_eq!(new_iarray, IArray::from(vec![1, 3, 4]));
27
+ /// ```
28
+ ///
29
+ /// This ensures that you can work with a mutable `Vec<T>` while still benefiting from
30
+ /// `IArray<T>`'s immutable properties when needed.
10
31
#[ derive( PartialEq , Eq ) ]
11
32
pub enum IArray < T : ImplicitClone + ' static > {
12
33
/// A static slice.
You can’t perform that action at this time.
0 commit comments