[−][src]Struct zc::Zc
Implementations
impl<O, D> Zc<O, D> where
O: Owner,
D: Dependant<'static> + 'static,
[src]
O: Owner,
D: Dependant<'static> + 'static,
pub fn new<C>(owner: O, constructor: C) -> Self where
C: for<'o> Construct<'o, <O::Storage as Deref>::Target, Dependant = D>,
[src]
C: for<'o> Construct<'o, <O::Storage as Deref>::Target, Dependant = D>,
Construct a new zero-copied structure given an Owner
and a
function for constructing the Dependant
.
Example
use zc::{Zc, Dependant}; #[derive(Dependant)] struct MyStruct<'a>(&'a [u8]); impl<'a> From<&'a [u8]> for MyStruct<'a> { fn from(bytes: &'a [u8]) -> Self { Self(&bytes[1..]) } } let owner = vec![1, 2, 3]; let _ = zc::from!(owner, MyStruct, [u8]);
pub fn try_new<C, E>(owner: O, constructor: C) -> Result<Self, (E, O)> where
E: 'static,
C: for<'o> TryConstruct<'o, <O::Storage as Deref>::Target, Error = E, Dependant = D>,
[src]
E: 'static,
C: for<'o> TryConstruct<'o, <O::Storage as Deref>::Target, Error = E, Dependant = D>,
Try construct a new zero-copied structure given an Owner
and a
function for constructing the Dependant
.
Example
use zc::{Zc, Dependant}; use core::convert::TryFrom; #[derive(Dependant)] struct MyStruct<'a>(&'a [u8]); impl<'a> TryFrom<&'a [u8]> for MyStruct<'a> { type Error = (); fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error> { Ok(Self(&bytes[1..])) } } let owner = vec![1, 2, 3]; let _ = zc::try_from!(owner, MyStruct, [u8]);
Errors
Returns E
if the constructor failed.
pub fn get<'a, T>(&'a self) -> &T where
T: Dependant<'a, Static = D>,
[src]
T: Dependant<'a, Static = D>,
Return a reference to the Dependant
.
The dependant type T
must be supplied (eg.
Self::dependant::<MyStruct>(&self)
).
Example
use zc::{Zc, Dependant}; #[derive(Debug, PartialEq, Dependant)] struct MyStruct<'a>(&'a [u8]); impl<'a> From<&'a [u8]> for MyStruct<'a> { fn from(bytes: &'a [u8]) -> Self { Self(&bytes[1..]) } } let owner = vec![1, 2, 3]; let data = zc::from!(owner, MyStruct, [u8]); assert_eq!( data.get::<MyStruct>(), &MyStruct(&[2, 3]) );
pub fn as_owned(&self) -> &<O::Storage as Deref>::Target
[src]
Return a reference to the data Owner
provides.
Example
use zc::{Zc, Dependant}; #[derive(Debug, PartialEq, Dependant)] struct MyStruct<'a>(&'a [u8]); impl<'a> From<&'a [u8]> for MyStruct<'a> { fn from(bytes: &'a [u8]) -> Self { Self(&bytes[1..]) } } let owner = vec![1, 2, 3]; let data = zc::from!(owner, MyStruct, [u8]); assert_eq!(data.as_owned(), &[1, 2, 3]);
pub fn into_owner(self) -> O
[src]
Consumes self
into the Owner
.
Example
use zc::{Zc, Dependant}; #[derive(Debug, PartialEq, Dependant)] struct MyStruct<'a>(&'a [u8]); impl<'a> From<&'a [u8]> for MyStruct<'a> { fn from(bytes: &'a [u8]) -> Self { Self(&bytes[1..]) } } let owner = vec![1, 2, 3]; let data = zc::from!(owner, MyStruct, [u8]); assert_eq!(data.into_owner(), vec![1, 2, 3]);
Trait Implementations
Auto Trait Implementations
impl<O, D> RefUnwindSafe for Zc<O, D> where
D: RefUnwindSafe,
<O as Owner>::Storage: RefUnwindSafe,
[src]
D: RefUnwindSafe,
<O as Owner>::Storage: RefUnwindSafe,
impl<O, D> Send for Zc<O, D> where
D: Send,
<O as Owner>::Storage: Send,
[src]
D: Send,
<O as Owner>::Storage: Send,
impl<O, D> Sync for Zc<O, D> where
D: Sync,
<O as Owner>::Storage: Sync,
[src]
D: Sync,
<O as Owner>::Storage: Sync,
impl<O, D> Unpin for Zc<O, D> where
D: Unpin,
<O as Owner>::Storage: Unpin,
[src]
D: Unpin,
<O as Owner>::Storage: Unpin,
impl<O, D> UnwindSafe for Zc<O, D> where
D: UnwindSafe,
<O as Owner>::Storage: UnwindSafe,
[src]
D: UnwindSafe,
<O as Owner>::Storage: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,