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>
impl<'a> Provider<'a>
Sourcepub fn type_match(&'a self) -> TypeMatch<'a>
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.
Sourcepub fn to_owned(self) -> Cell
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.
Sourcepub fn to_borrowed(self, origin: &Origin) -> RuntimeResult<&'a mut Cell>
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.