Skip to main content

Dependant

Trait Dependant 

Source
pub unsafe trait Dependant<'o>: Sized + 'o {
    type Static: Dependant<'static>;
}
Expand description

Implemented for types that use data provided by an Owner and guarantee that internal state is protected.

It is recommended not to implement this manually and instead use the provided proc-macro as show below.

use zc::Dependant;

#[derive(Dependant)]
pub struct MyStruct<'a> {
    value: &'a str,
}

§Derive implementations for Copy

If a type implements Copy it cannot support interior mutability and therefore is a valid Dependant type.

To use a Copy type without having to implement Dependant you can tell the derive implementation to check based on a Copy bound for a specific field or all fields.

use zc::Dependant;

#[derive(Copy, Clone)]
pub struct CopyType;

#[derive(Dependant)]
pub struct StructWithCopy<'a> {
    // This field has a `Copy` bound.
    #[zc(check = "Copy")]
    field_a: &'a CopyType,
    // This field has the standard `Dependant` bound.
    field_b: u8,
}

// All fields in this struct have the `Copy` bound.
#[derive(Dependant)]
#[zc(check = "Copy")]
pub struct StructWithAllCopy<'a> {
    field_a: &'a CopyType,
    field_b: u8,
}

§Manual implementations

If you wish not to use the provided proc-macro you implement as shown:

struct MyStruct<'a>(&'a [u8]);

unsafe impl<'o> zc::Dependant<'o> for MyStruct<'o> {
    type Static = MyStruct<'static>;
}

§Safety

Implementer must guarantee:

  • the structure only requires a single lifetime.
  • Self::Static must be the same type but with a 'static lifetime.

And in addition the structure:

  • has no interior mutability.

OR

  • can safely be stored with it’s lifetime erased (ie. as 'static).
  • does not provided an interface that will accept data with non-'static lifetime though a interior mutable interface.

§Interior Mutability

Types that provide interior mutability include both !Sync types (eg. RefCell<T>) and Sync types (eg. Mutex<T>).

See the Rust Language Book on interior mutability.

Required Associated Types§

Source

type Static: Dependant<'static>

Always the exact same structure as Self but instead with a 'static lifetime.

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.

Implementations on Foreign Types§

Source§

impl<'o> Dependant<'o> for &'o str

Source§

type Static = &'static str

Source§

impl<'o> Dependant<'o> for &'o [u8]

Source§

type Static = &'static [u8]

Source§

impl<'o> Dependant<'o> for bool

Source§

impl<'o> Dependant<'o> for char

Source§

impl<'o> Dependant<'o> for f32

Source§

impl<'o> Dependant<'o> for f64

Source§

impl<'o> Dependant<'o> for i8

Source§

impl<'o> Dependant<'o> for i16

Source§

impl<'o> Dependant<'o> for i32

Source§

impl<'o> Dependant<'o> for i64

Source§

impl<'o> Dependant<'o> for i128

Source§

impl<'o> Dependant<'o> for isize

Source§

impl<'o> Dependant<'o> for u8

Source§

impl<'o> Dependant<'o> for u16

Source§

impl<'o> Dependant<'o> for u32

Source§

impl<'o> Dependant<'o> for u64

Source§

impl<'o> Dependant<'o> for u128

Source§

impl<'o> Dependant<'o> for ()

Source§

impl<'o> Dependant<'o> for usize

Source§

impl<'o> Dependant<'o> for String

Source§

impl<'o> Dependant<'o> for NonZeroI8

Source§

impl<'o> Dependant<'o> for NonZeroI16

Source§

impl<'o> Dependant<'o> for NonZeroI32

Source§

impl<'o> Dependant<'o> for NonZeroI64

Source§

impl<'o> Dependant<'o> for NonZeroI128

Source§

impl<'o> Dependant<'o> for NonZeroIsize

Source§

impl<'o> Dependant<'o> for NonZeroU8

Source§

impl<'o> Dependant<'o> for NonZeroU16

Source§

impl<'o> Dependant<'o> for NonZeroU32

Source§

impl<'o> Dependant<'o> for NonZeroU64

Source§

impl<'o> Dependant<'o> for NonZeroU128

Source§

impl<'o> Dependant<'o> for NonZeroUsize

Source§

impl<'o, K, V> Dependant<'o> for BTreeMap<K, V>
where K: Dependant<'o>, V: Dependant<'o>,

Source§

type Static = BTreeMap<<K as Dependant<'o>>::Static, <V as Dependant<'o>>::Static>

Source§

impl<'o, K, V, S> Dependant<'o> for HashMap<K, V, S>
where K: Dependant<'o>, V: Dependant<'o>, S: BuildHasher + 'static,

Source§

type Static = HashMap<<K as Dependant<'o>>::Static, <V as Dependant<'o>>::Static, S>

Source§

impl<'o, T1: Dependant<'o>> Dependant<'o> for (T1,)

Source§

type Static = (<T1 as Dependant<'o>>::Static,)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>> Dependant<'o> for (T1, T2)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>, T3: Dependant<'o>> Dependant<'o> for (T1, T2, T3)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static, <T3 as Dependant<'o>>::Static)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>, T3: Dependant<'o>, T4: Dependant<'o>> Dependant<'o> for (T1, T2, T3, T4)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static, <T3 as Dependant<'o>>::Static, <T4 as Dependant<'o>>::Static)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>, T3: Dependant<'o>, T4: Dependant<'o>, T5: Dependant<'o>> Dependant<'o> for (T1, T2, T3, T4, T5)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static, <T3 as Dependant<'o>>::Static, <T4 as Dependant<'o>>::Static, <T5 as Dependant<'o>>::Static)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>, T3: Dependant<'o>, T4: Dependant<'o>, T5: Dependant<'o>, T6: Dependant<'o>> Dependant<'o> for (T1, T2, T3, T4, T5, T6)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static, <T3 as Dependant<'o>>::Static, <T4 as Dependant<'o>>::Static, <T5 as Dependant<'o>>::Static, <T6 as Dependant<'o>>::Static)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>, T3: Dependant<'o>, T4: Dependant<'o>, T5: Dependant<'o>, T6: Dependant<'o>, T7: Dependant<'o>> Dependant<'o> for (T1, T2, T3, T4, T5, T6, T7)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static, <T3 as Dependant<'o>>::Static, <T4 as Dependant<'o>>::Static, <T5 as Dependant<'o>>::Static, <T6 as Dependant<'o>>::Static, <T7 as Dependant<'o>>::Static)

Source§

impl<'o, T1: Dependant<'o>, T2: Dependant<'o>, T3: Dependant<'o>, T4: Dependant<'o>, T5: Dependant<'o>, T6: Dependant<'o>, T7: Dependant<'o>, T8: Dependant<'o>> Dependant<'o> for (T1, T2, T3, T4, T5, T6, T7, T8)

Source§

type Static = (<T1 as Dependant<'o>>::Static, <T2 as Dependant<'o>>::Static, <T3 as Dependant<'o>>::Static, <T4 as Dependant<'o>>::Static, <T5 as Dependant<'o>>::Static, <T6 as Dependant<'o>>::Static, <T7 as Dependant<'o>>::Static, <T8 as Dependant<'o>>::Static)

Source§

impl<'o, T, E> Dependant<'o> for Result<T, E>
where T: Dependant<'o>, E: Dependant<'o>,

Source§

type Static = Result<<T as Dependant<'o>>::Static, <E as Dependant<'o>>::Static>

Source§

impl<'o, T, S> Dependant<'o> for HashSet<T, S>
where T: Dependant<'o>, S: BuildHasher + 'static,

Source§

type Static = HashSet<<T as Dependant<'o>>::Static, S>

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for Option<T>

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 1]

Source§

type Static = [<T as Dependant<'o>>::Static; 1]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 2]

Source§

type Static = [<T as Dependant<'o>>::Static; 2]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 3]

Source§

type Static = [<T as Dependant<'o>>::Static; 3]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 4]

Source§

type Static = [<T as Dependant<'o>>::Static; 4]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 5]

Source§

type Static = [<T as Dependant<'o>>::Static; 5]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 6]

Source§

type Static = [<T as Dependant<'o>>::Static; 6]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 7]

Source§

type Static = [<T as Dependant<'o>>::Static; 7]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 8]

Source§

type Static = [<T as Dependant<'o>>::Static; 8]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 9]

Source§

type Static = [<T as Dependant<'o>>::Static; 9]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 10]

Source§

type Static = [<T as Dependant<'o>>::Static; 10]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 11]

Source§

type Static = [<T as Dependant<'o>>::Static; 11]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 12]

Source§

type Static = [<T as Dependant<'o>>::Static; 12]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 13]

Source§

type Static = [<T as Dependant<'o>>::Static; 13]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 14]

Source§

type Static = [<T as Dependant<'o>>::Static; 14]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 15]

Source§

type Static = [<T as Dependant<'o>>::Static; 15]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 16]

Source§

type Static = [<T as Dependant<'o>>::Static; 16]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 17]

Source§

type Static = [<T as Dependant<'o>>::Static; 17]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 18]

Source§

type Static = [<T as Dependant<'o>>::Static; 18]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 19]

Source§

type Static = [<T as Dependant<'o>>::Static; 19]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 20]

Source§

type Static = [<T as Dependant<'o>>::Static; 20]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 21]

Source§

type Static = [<T as Dependant<'o>>::Static; 21]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 22]

Source§

type Static = [<T as Dependant<'o>>::Static; 22]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 23]

Source§

type Static = [<T as Dependant<'o>>::Static; 23]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 24]

Source§

type Static = [<T as Dependant<'o>>::Static; 24]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 25]

Source§

type Static = [<T as Dependant<'o>>::Static; 25]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 26]

Source§

type Static = [<T as Dependant<'o>>::Static; 26]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 27]

Source§

type Static = [<T as Dependant<'o>>::Static; 27]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 28]

Source§

type Static = [<T as Dependant<'o>>::Static; 28]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 29]

Source§

type Static = [<T as Dependant<'o>>::Static; 29]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 30]

Source§

type Static = [<T as Dependant<'o>>::Static; 30]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 31]

Source§

type Static = [<T as Dependant<'o>>::Static; 31]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for [T; 32]

Source§

type Static = [<T as Dependant<'o>>::Static; 32]

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for &'o T

Source§

type Static = &'static <T as Dependant<'o>>::Static

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for BinaryHeap<T>

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for BTreeSet<T>

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for Vec<T>

Source§

type Static = Vec<<T as Dependant<'o>>::Static>

Source§

impl<'o, T: Dependant<'o>> Dependant<'o> for Wrapping<T>

Implementors§