pub trait Pointer {
type Of<'a, T: ?Sized + 'a>: Deref<Target = T> + 'a;
// Required method
fn new<'a, T: 'a>(value: T) -> Self::Of<'a, T>
where Self::Of<'a, T>: Sized;
}Expand description
Base type class for heap-allocated pointers.
This is the minimal abstraction: any type that can wrap a value and dereference to it. Does NOT require Clone - that’s added by subtraits.
By explicitly requiring that the type parameter T outlives the application lifetime 'a,
we provide the compiler with the necessary guarantees to handle trait objects
(like dyn Fn) commonly used in pointer implementations. This resolves potential
E0310 errors where the compiler cannot otherwise prove that captured variables in
closures satisfy the required lifetime bounds.
Required Associated Types§
Required Methods§
Sourcefn new<'a, T: 'a>(value: T) -> Self::Of<'a, T>
fn new<'a, T: 'a>(value: T) -> Self::Of<'a, T>
Wraps a sized value in the pointer.
§Type Signature
forall T. T -> Self T
§Type Parameters
'a: The lifetime of the value.T: The type of the value to wrap.
§Parameters
value: The value to wrap.
§Returns
The value wrapped in the pointer type.
§Examples
use fp_library::{
brands::*,
classes::*,
};
let ptr = <RcBrand as Pointer>::new(42);
assert_eq!(*ptr, 42);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.