[][src]Trait zc::Dependant

pub unsafe trait Dependant<'a>: Sized + Guarded {
    type Static: Dependant<'static> + 'static;
    pub unsafe fn erase_lifetime(self) -> Self::Static;
}

Implemented for types that use data provided by an Owner.

Implementation (recommended)

It is recommeneded 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,
}

Implementation (manual)

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

use zc::NoInteriorMut;

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

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

    unsafe fn erase_lifetime(self) -> Self::Static {
        core::mem::transmute(self)
    }
}

Safety

Implementer must guarantee:

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

Associated Types

type Static: Dependant<'static> + 'static[src]

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

Loading content...

Required methods

pub unsafe fn erase_lifetime(self) -> Self::Static[src]

Erases the Dependant's lifetime by returning a static variant.

Safety

The value returned is for use by the Zc structure only.

Loading content...

Implementors

Loading content...