Struct zc::Zc [−][src]
Implementations
impl<O, D> Zc<O, D> where
O: Owner,
D: Dependant<'static>,
[src]
O: Owner,
D: Dependant<'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]) );
impl<O, D> Zc<O, D> where
O: Owner,
[src]
O: Owner,
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]);
pub unsafe fn map_unchecked<F, U>(self, f: F) -> Zc<O, U> where
F: FnOnce(D) -> U,
[src]
F: FnOnce(D) -> U,
Map the stored Dependant
to another.
Safety
The Dependant
passed to the function has its lifetime erased to
'static
and must be handled appropriately. Nothing within the
Dependant
passed can be referenced from outside of the closure.
pub unsafe fn try_map_unchecked<F, U, E>(self, f: F) -> Result<Zc<O, U>, E> where
F: FnOnce(D) -> Result<U, E>,
[src]
F: FnOnce(D) -> Result<U, E>,
Try to map the stored Dependant
to another.
Errors
Returns any error the provided function returns.
Safety
The Dependant
passed to the function has its lifetime erased to
'static
and must be handled appropriately. Nothing within the
Dependant
passed can be referenced from outside of the closure,
this includes the error returned.
impl<O, T> Zc<O, Option<T>> where
O: Owner,
[src]
O: Owner,
pub fn into_option(self) -> Option<Zc<O, T>>
[src]
Decomposes self
into an option.
impl<O, Ok, Err> Zc<O, Result<Ok, Err>> where
O: Owner,
[src]
O: Owner,
pub fn into_result(self) -> Result<Zc<O, Ok>, Zc<O, Err>>
[src]
Trait Implementations
impl<O, D> Debug for Zc<O, D> where
O: Owner,
O::Storage: Debug,
D: Debug,
[src]
O: Owner,
O::Storage: Debug,
D: Debug,
impl<O, D> Display for Zc<O, D> where
O: Owner,
D: Display,
[src]
O: Owner,
D: Display,
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> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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>,