Skip to main content

Owned

Struct Owned 

Source
pub struct Owned<Y: for<'a> Yokeable<'a>> { /* private fields */ }
Expand description

An owned, 'static, Send + Sync bundle of (backing bytes, parsed view).

Y is the view type with its lifetime set to 'static — e.g. Owned<Pmt<'static>>, Owned<Sdt<'static>>, Owned<DescriptorLoop<'static>>. The backing buffer is an Arc<[u8]>, so Clone is a refcount bump and the view is shared, never re-parsed.

Construct one with Owned::try_new (fallible parse) or Owned::new (infallible), then read the borrowing view with Owned::get.

Implementations§

Source§

impl<Y: for<'a> Yokeable<'a>> Owned<Y>

Source

pub fn try_new<F, E>(bytes: Arc<[u8]>, parse: F) -> Result<Self, E>
where F: for<'a> FnOnce(&'a [u8]) -> Result<<Y as Yokeable<'a>>::Output, E>,

Parse bytes into a view and bundle the two into an Owned.

parse receives a borrow of the backing bytes and returns the borrowing view (or an error). The borrow does not escape parse: yoke re-binds the view’s lifetime to the Arc<[u8]> it now co-owns.

§Errors

Returns parse’s error verbatim if parsing fails.

Source

pub fn new<F>(bytes: Arc<[u8]>, parse: F) -> Self
where F: for<'a> FnOnce(&'a [u8]) -> <Y as Yokeable<'a>>::Output,

Parse bytes into a view with an infallible parser and bundle them.

Source

pub fn get(&self) -> &<Y as Yokeable<'_>>::Output

Borrow the parsed view. No re-parse; this is a field read.

Source

pub fn backing_bytes(&self) -> &[u8]

The backing section bytes the view borrows from.

Trait Implementations§

Source§

impl<Y: for<'a> Yokeable<'a>> Clone for Owned<Y>
where for<'a> YokeTraitHack<<Y as Yokeable<'a>>::Output>: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Y> Debug for Owned<Y>
where Y: for<'a> Yokeable<'a>, for<'a> <Y as Yokeable<'a>>::Output: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Y> Freeze for Owned<Y>
where Y: Freeze,

§

impl<Y> RefUnwindSafe for Owned<Y>
where Y: RefUnwindSafe,

§

impl<Y> Send for Owned<Y>
where Y: Send,

§

impl<Y> Sync for Owned<Y>
where Y: Sync,

§

impl<Y> Unpin for Owned<Y>
where Y: Unpin,

§

impl<Y> UnsafeUnpin for Owned<Y>
where Y: UnsafeUnpin,

§

impl<Y> UnwindSafe for Owned<Y>
where Y: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.