1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! Thread-safe reference-counted pointers that carry `Send + Sync` bounds.
//!
//! ### Examples
//!
//! ```
//! use fp_library::{
//! brands::*,
//! functions::*,
//! };
//!
//! let ptr = send_ref_counted_pointer_new::<ArcBrand, _>(42);
//! assert_eq!(*ptr, 42);
//! ```
#[fp_macros::document_module]
mod inner {
use {
crate::classes::*,
fp_macros::*,
std::ops::Deref,
};
/// Extension trait for thread-safe reference-counted pointers.
///
/// This follows the same pattern as `SendCloneFn` extends `CloneFn`,
/// adding a `SendOf` associated type with explicit `Send + Sync` bounds.
pub trait SendRefCountedPointer: RefCountedPointer {
/// The thread-safe pointer type constructor.
///
/// For `ArcBrand`, this is `Arc<T>` where `T: Send + Sync`.
type SendOf<'a, T: ?Sized + Send + Sync + 'a>: Clone + Send + Sync + Deref<Target = T> + 'a;
/// Wraps a sized value in a thread-safe pointer.
#[document_signature]
///
#[document_type_parameters("The lifetime of the value.", "The type of the value to wrap.")]
///
#[document_parameters("The value to wrap.")]
///
#[document_returns("The value wrapped in the thread-safe pointer type.")]
#[document_examples]
///
/// ```
/// use fp_library::{
/// brands::*,
/// functions::*,
/// };
///
/// let ptr = send_ref_counted_pointer_new::<ArcBrand, _>(42);
/// assert_eq!(*ptr, 42);
/// ```
fn send_new<'a, T: Send + Sync + 'a>(value: T) -> Self::SendOf<'a, T>
where
Self::SendOf<'a, T>: Sized;
}
/// Wraps a sized value in a thread-safe pointer.
#[document_signature]
///
#[document_type_parameters(
"The pointer brand.",
"The lifetime of the value.",
"The type of the value to wrap."
)]
///
#[document_parameters("The value to wrap.")]
///
#[document_returns("The value wrapped in the thread-safe pointer type.")]
#[document_examples]
///
/// ```
/// use fp_library::{
/// brands::*,
/// functions::*,
/// };
///
/// let ptr = send_ref_counted_pointer_new::<ArcBrand, _>(42);
/// assert_eq!(*ptr, 42);
/// ```
pub fn send_new<'a, P: SendRefCountedPointer, T: Send + Sync + 'a>(
value: T
) -> P::SendOf<'a, T>
where
P::SendOf<'a, T>: Sized, {
P::send_new(value)
}
}
pub use inner::*;