Skip to main content

ExtValue

Struct ExtValue 

Source
pub struct ExtValue<'a>(/* private fields */);
Expand description

An extension value carried by Atom::Ext.

The value is either borrowed (which is typical during serialization and for values that formats create while parsing) or owned. Owned values are reference counted, so cloning an extension value is cheap.

Extension values are covariant in their lifetime and they can borrow data (see BorrowedExtension).

Implementations§

Source§

impl<'a> ExtValue<'a>

Source

pub fn borrowed<T: Extension>(value: &'a T) -> ExtValue<'a>

Creates an extension value borrowing from a value.

Source

pub fn owned<T: Extension>(value: T) -> ExtValue<'a>

Creates an extension value that owns the value.

Source

pub fn borrowed_value<K: BorrowedExtension>( value: &'a K::Value<'a>, ) -> ExtValue<'a>

Creates an extension value borrowing from the value of an extension.

The extension is identified by its key K (see BorrowedExtension).

Source

pub fn owned_value<K: BorrowedExtension>(value: K::Value<'a>) -> ExtValue<'a>

Creates an extension value that owns the value of an extension.

The extension is identified by its key K (see BorrowedExtension).

Source

pub fn name(&self) -> &str

Returns the human readable name of the extension type.

Source

pub fn fallback(&self) -> Atom<'_>

Returns the fallback atom of the value.

See Extension::fallback.

Source

pub fn is<K: BorrowedExtension>(&self) -> bool

Returns true if the value is of the extension with the key K.

For extensions without lifetimes the key is the type.

Source

pub fn downcast_ref<T: Extension>(&self) -> Option<&T>

Returns the value if it’s of type T.

use deser::ext::ExtValue;

let ext = ExtValue::owned(42u128);
assert_eq!(ext.downcast_ref::<u128>(), Some(&42));

For extensions that borrow use downcast_value_ref.

Source

pub fn downcast_value_ref<K: BorrowedExtension>(&self) -> Option<&K::Value<'_>>

Returns the value if it’s of the extension with the key K.

See BorrowedExtension for an example. The returned value borrows from this extension value.

Source

pub fn as_borrowed(&self) -> ExtValue<'_>

Returns a value borrowing from this one.

Source

pub fn to_static(&self) -> ExtValue<'static>

Makes a static clone of the value decoupling the lifetimes.

Values that borrow data are detached from it (see BorrowedExtension::to_static).

Trait Implementations§

Source§

impl<'a> Clone for ExtValue<'a>

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<'a> Debug for ExtValue<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for ExtValue<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ExtValue<'a>

§

impl<'a> !UnwindSafe for ExtValue<'a>

§

impl<'a> Freeze for ExtValue<'a>

§

impl<'a> Send for ExtValue<'a>

§

impl<'a> Sync for ExtValue<'a>

§

impl<'a> Unpin for ExtValue<'a>

§

impl<'a> UnsafeUnpin for ExtValue<'a>

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.