Trait zc::Dependant [−][src]
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.
Implementations on Foreign Types
impl<'o> Dependant<'o> for &'o str
[src]
impl<'o> Dependant<'o> for &'o [u8]
[src]
type Static = &'static [u8]
impl<'o> Dependant<'o> for ()
[src]
impl<'o> Dependant<'o> for bool
[src]
impl<'o> Dependant<'o> for char
[src]
impl<'o> Dependant<'o> for f32
[src]
impl<'o> Dependant<'o> for f64
[src]
impl<'o> Dependant<'o> for isize
[src]
impl<'o> Dependant<'o> for usize
[src]
impl<'o> Dependant<'o> for u8
[src]
impl<'o> Dependant<'o> for u16
[src]
impl<'o> Dependant<'o> for u32
[src]
impl<'o> Dependant<'o> for u64
[src]
impl<'o> Dependant<'o> for u128
[src]
impl<'o> Dependant<'o> for i8
[src]
impl<'o> Dependant<'o> for i16
[src]
impl<'o> Dependant<'o> for i32
[src]
impl<'o> Dependant<'o> for i64
[src]
impl<'o> Dependant<'o> for i128
[src]
impl<'o> Dependant<'o> for NonZeroI8
[src]
impl<'o> Dependant<'o> for NonZeroI16
[src]
type Static = NonZeroI16
impl<'o> Dependant<'o> for NonZeroI32
[src]
type Static = NonZeroI32
impl<'o> Dependant<'o> for NonZeroI64
[src]
type Static = NonZeroI64
impl<'o> Dependant<'o> for NonZeroI128
[src]
type Static = NonZeroI128
impl<'o> Dependant<'o> for NonZeroIsize
[src]
type Static = NonZeroIsize
impl<'o> Dependant<'o> for NonZeroU8
[src]
impl<'o> Dependant<'o> for NonZeroU16
[src]
type Static = NonZeroU16
impl<'o> Dependant<'o> for NonZeroU32
[src]
type Static = NonZeroU32
impl<'o> Dependant<'o> for NonZeroU64
[src]
type Static = NonZeroU64
impl<'o> Dependant<'o> for NonZeroU128
[src]
type Static = NonZeroU128
impl<'o> Dependant<'o> for NonZeroUsize
[src]
type Static = NonZeroUsize
impl<'o, T: Dependant<'o>> Dependant<'o> for &'o T
[src]
impl<'o, T: Dependant<'o>> Dependant<'o> for Option<T>
[src]
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]
T: Dependant<'o>,
E: Dependant<'o>,
impl<'o> Dependant<'o> for String
[src]
impl<'o, T: Dependant<'o>> Dependant<'o> for Vec<T>
[src]
impl<'o, T: Dependant<'o>> Dependant<'o> for BTreeSet<T>
[src]
impl<'o, T: Dependant<'o>> Dependant<'o> for BinaryHeap<T>
[src]
type Static = BinaryHeap<T::Static>
impl<'o, K, V> Dependant<'o> for BTreeMap<K, V> where
K: Dependant<'o>,
V: Dependant<'o>,
[src]
K: Dependant<'o>,
V: Dependant<'o>,
impl<'o, T, S> Dependant<'o> for HashSet<T, S> where
T: Dependant<'o>,
S: BuildHasher + 'static,
[src]
T: Dependant<'o>,
S: BuildHasher + 'static,
impl<'o, K, V, S> Dependant<'o> for HashMap<K, V, S> where
K: Dependant<'o>,
V: Dependant<'o>,
S: BuildHasher + 'static,
[src]
K: Dependant<'o>,
V: Dependant<'o>,
S: BuildHasher + 'static,