Skip to main content

Pointer

Trait Pointer 

Source
pub trait Pointer {
    type Of<T: ?Sized>: Deref<Target = T>;

    // Required method
    fn new<T>(value: T) -> Self::Of<T>
       where Self::Of<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.

Required Associated Types§

Source

type Of<T: ?Sized>: Deref<Target = T>

The pointer type constructor.

For RcBrand, this is Rc<T>. For BoxBrand, this would be Box<T>.

Required Methods§

Source

fn new<T>(value: T) -> Self::Of<T>
where Self::Of<T>: Sized,

Wraps a sized value in the pointer.

§Type Signature

forall self t. t -> self t

§Type Parameters
  • 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.

Implementors§

Source§

impl Pointer for ArcBrand

Source§

type Of<T: ?Sized> = Arc<T>

Source§

impl Pointer for RcBrand

Source§

type Of<T: ?Sized> = Rc<T>