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>
impl<'a> ExtValue<'a>
Sourcepub fn borrowed<T: Extension>(value: &'a T) -> ExtValue<'a>
pub fn borrowed<T: Extension>(value: &'a T) -> ExtValue<'a>
Creates an extension value borrowing from a value.
Sourcepub fn owned<T: Extension>(value: T) -> ExtValue<'a>
pub fn owned<T: Extension>(value: T) -> ExtValue<'a>
Creates an extension value that owns the value.
Sourcepub fn borrowed_value<K: BorrowedExtension>(
value: &'a K::Value<'a>,
) -> ExtValue<'a>
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).
Sourcepub fn owned_value<K: BorrowedExtension>(value: K::Value<'a>) -> ExtValue<'a>
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).
Sourcepub fn fallback(&self) -> Atom<'_>
pub fn fallback(&self) -> Atom<'_>
Returns the fallback atom of the value.
See Extension::fallback.
Sourcepub fn is<K: BorrowedExtension>(&self) -> bool
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.
Sourcepub fn downcast_ref<T: Extension>(&self) -> Option<&T>
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.
Sourcepub fn downcast_value_ref<K: BorrowedExtension>(&self) -> Option<&K::Value<'_>>
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.
Sourcepub fn as_borrowed(&self) -> ExtValue<'_>
pub fn as_borrowed(&self) -> ExtValue<'_>
Returns a value borrowing from this one.
Sourcepub fn to_static(&self) -> ExtValue<'static>
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).