abin/common/sync.rs
1/// Converts this into a synchronized version.
2///
3/// See also `IntoUnSyncView`, `IntoUnSync` and `UnSyncRef`.
4pub trait IntoSync {
5 type Target;
6
7 /// Converts this into a synchronized version.
8 ///
9 /// It's cheap if this is already backed by a synchronized implementation (or if it's just a
10 /// view). See also `IntoUnSyncView` / `IntoUnSync`. If it's not
11 /// backed by a synchronized implementation, this operation might be expensive: for instance
12 /// if you apply this operation on a reference-counted binary that's not synchronized and has
13 /// multiple references pointing to it, the data of the binary must be cloned.
14 ///
15 /// ```rust
16 /// use abin::{NewBin, Bin, BinFactory, SBin, IntoSync, NewSBin, AnyBin};
17 ///
18 /// let string = "this is the content of this binary";
19 /// let not_sync : Bin = NewBin::copy_from_slice(string.as_bytes());
20 /// // this line 'converts' (not just a view) the binary into a sync binary (after that call
21 /// // the reference-counter is synchronized).
22 /// let sync_1 : SBin = not_sync.into_sync();
23 /// // this is the direct way to construct a synchronized binary.
24 /// // sync_1 and sync_2 are equivalent.
25 /// let sync_2 : SBin = NewSBin::copy_from_slice(string.as_bytes());
26 /// assert_eq!(string.as_bytes(), sync_1.as_slice());
27 /// assert_eq!(sync_1, sync_2);
28 /// ```
29 fn into_sync(self) -> Self::Target;
30}