pub struct UnchangedOr<T: ContainerElement = Any> { /* private fields */ }Expand description
A typed replacement or an Unchanged marker, stored in one FFI Any cell.
T may be an FFI value type or Any. Use Result<UnchangedOr<T>> to
propagate errors. Callbacks can return this wrapper, Unchanged, a
replacement value, or a Result containing any of these.
Converting this wrapper to Any preserves the marker. Use
Self::value_or or Self::value_or_else when an actual value is needed.
Implementations§
Source§impl<T: ContainerElement> UnchangedOr<T>
impl<T: ContainerElement> UnchangedOr<T>
Sourcepub fn is_unchanged(&self) -> bool
pub fn is_unchanged(&self) -> bool
Whether this result asks its caller to keep the original value.
Sourcepub fn unchanged_or_same_as(&self, original: &T) -> bool
pub fn unchanged_or_same_as(&self, original: &T) -> bool
Whether the result is unchanged or has the original shallow identity.
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Move out the replacement, returning None when unchanged.
Sourcepub fn value_or(self, original: T) -> T
pub fn value_or(self, original: T) -> T
Move the replacement or the supplied original value out of this result.
Sourcepub fn value_or_else(self, original: impl FnOnce() -> T) -> T
pub fn value_or_else(self, original: impl FnOnce() -> T) -> T
Materialize the original only if this result is unchanged.
Sourcepub fn map<U: ContainerElement>(
self,
convert: impl FnOnce(T) -> U,
) -> UnchangedOr<U>
pub fn map<U: ContainerElement>( self, convert: impl FnOnce(T) -> U, ) -> UnchangedOr<U>
Convert only the replacement, preserving an unchanged marker.
Sourcepub fn try_map<U: ContainerElement, E>(
self,
convert: impl FnOnce(T) -> Result<U, E>,
) -> Result<UnchangedOr<U>, E>
pub fn try_map<U: ContainerElement, E>( self, convert: impl FnOnce(T) -> Result<U, E>, ) -> Result<UnchangedOr<U>, E>
Fallibly convert only the replacement, propagating its error unchanged.
Sourcepub fn try_cast<U: ContainerElement>(self) -> Result<UnchangedOr<U>>
pub fn try_cast<U: ContainerElement>(self) -> Result<UnchangedOr<U>>
Check a replacement’s FFI type without cloning it.
An unchanged result is compatible with every replacement type. Erased
and narrowing conversions retain the strict type check used by
Any::try_as. For a known typed conversion, use map(Into::into).