Skip to main content

Provider

Enum Provider 

Source
pub enum Provider<'a> {
    Owned(Cell),
    Borrowed(&'a mut Cell),
}
Expand description

A wrapper around a Cell that provides either borrowing or owning access to the Cell’s data.

This object is used as a parameter for the Downcast::downcast function.

If the Provider owns a Cell (via the Owned variant) or borrows it (via the Borrowed variant), the downcast function can take ownership of the Cell’s data. However, the downcast function can only dereference the data of the Cell if the Provider is borrowing this Cell.

For more details, see the Downcast’s Lifetime documentation.

Variants§

§

Owned(Cell)

The Provider only provides ownership access to the Cell’s data.

§

Borrowed(&'a mut Cell)

The Provider provides both ownership and dereferencing access to the Cell.

Implementations§

Source§

impl<'a> Provider<'a>

Source

pub fn type_match(&'a self) -> TypeMatch<'a>

Provides a convenient helper interface for handling Cell data based on the Cell type.

This function is similar to Cell::type_match.

For more details, see TypeMatch.

Source

pub fn to_owned(self) -> Cell

Takes ownership of the Provider’s Cell.

This function is infallible regardless of the Provider’s variant. If the variant is Borrowed, this function replaces the referenced instance with Cell::nil and returns the original Cell instance.

Source

pub fn to_borrowed(self, origin: &Origin) -> RuntimeResult<&'a mut Cell>

Takes a mutable reference to the Provider’s Cell.

If the Provider’s variant is Borrowed, the function returns the underlying mutable reference; otherwise, it returns a RuntimeError.

The origin parameter specifies the source code range in Rust or Script where the data of the Cell is about to be accessed. This parameter is used to create an error if the Provider’s variant is Owned.

Trait Implementations§

Source§

impl<'a> AsRef<Cell> for Provider<'a>

Source§

fn as_ref(&self) -> &Cell

Converts this type into a shared reference of the (usually inferred) input type.

Auto Trait Implementations§

§

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

§

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

§

impl<'a> Freeze for Provider<'a>

§

impl<'a> Send for Provider<'a>

§

impl<'a> Sync for Provider<'a>

§

impl<'a> Unpin for Provider<'a>

§

impl<'a> UnsafeUnpin for Provider<'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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.