Trait zc::Dependant[][src]

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

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

Derive implementations (recommended)

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.

Associated Types

type Static: Dependant<'static>[src]

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

Loading content...

Implementations on Foreign Types

impl<'o> Dependant<'o> for &'o str[src]

type Static = &'static str

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

impl<'o> Dependant<'o> for ()[src]

type Static = ()

impl<'o> Dependant<'o> for bool[src]

type Static = bool

impl<'o> Dependant<'o> for char[src]

type Static = char

impl<'o> Dependant<'o> for f32[src]

type Static = f32

impl<'o> Dependant<'o> for f64[src]

type Static = f64

impl<'o> Dependant<'o> for isize[src]

type Static = isize

impl<'o> Dependant<'o> for usize[src]

type Static = usize

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

type Static = u8

impl<'o> Dependant<'o> for u16[src]

type Static = u16

impl<'o> Dependant<'o> for u32[src]

type Static = u32

impl<'o> Dependant<'o> for u64[src]

type Static = u64

impl<'o> Dependant<'o> for u128[src]

type Static = u128

impl<'o> Dependant<'o> for i8[src]

type Static = i8

impl<'o> Dependant<'o> for i16[src]

type Static = i16

impl<'o> Dependant<'o> for i32[src]

type Static = i32

impl<'o> Dependant<'o> for i64[src]

type Static = i64

impl<'o> Dependant<'o> for i128[src]

type Static = i128

impl<'o> Dependant<'o> for NonZeroI8[src]

impl<'o> Dependant<'o> for NonZeroI16[src]

impl<'o> Dependant<'o> for NonZeroI32[src]

impl<'o> Dependant<'o> for NonZeroI64[src]

impl<'o> Dependant<'o> for NonZeroI128[src]

impl<'o> Dependant<'o> for NonZeroIsize[src]

impl<'o> Dependant<'o> for NonZeroU8[src]

impl<'o> Dependant<'o> for NonZeroU16[src]

impl<'o> Dependant<'o> for NonZeroU32[src]

impl<'o> Dependant<'o> for NonZeroU64[src]

impl<'o> Dependant<'o> for NonZeroU128[src]

impl<'o> Dependant<'o> for NonZeroUsize[src]

impl<'o, T: Dependant<'o>> Dependant<'o> for &'o T[src]

type Static = &'static T::Static

impl<'o, T: Dependant<'o>> Dependant<'o> for Option<T>[src]

type Static = Option<T::Static>

impl<'o, T: Dependant<'o>> Dependant<'o> for Wrapping<T>[src]

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

type Static = Result<T::Static, E::Static>

impl<'o> Dependant<'o> for String[src]

type Static = String

impl<'o, T: Dependant<'o>> Dependant<'o> for Vec<T>[src]

type Static = Vec<T::Static>

impl<'o, T: Dependant<'o>> Dependant<'o> for BTreeSet<T>[src]

impl<'o, T: Dependant<'o>> Dependant<'o> for BinaryHeap<T>[src]

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

type Static = BTreeMap<K::Static, V::Static>

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

type Static = HashSet<T::Static, S>

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

type Static = HashMap<K::Static, V::Static, S>

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

type Static = (T1::Static,)

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

type Static = (T1::Static, T2::Static)

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

type Static = (T1::Static, T2::Static, T3::Static)

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

type Static = (T1::Static, T2::Static, T3::Static, T4::Static)

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)[src]

type Static = (T1::Static, T2::Static, T3::Static, T4::Static, T5::Static)

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)[src]

type Static = (T1::Static, T2::Static, T3::Static, T4::Static, T5::Static, T6::Static)

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)[src]

type Static = (T1::Static, T2::Static, T3::Static, T4::Static, T5::Static, T6::Static, T7::Static)

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)[src]

type Static = (T1::Static, T2::Static, T3::Static, T4::Static, T5::Static, T6::Static, T7::Static, T8::Static)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading content...

Implementors

Loading content...