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).
Trait Implementations§
Source§impl<T: ContainerElement> AnyCompatible for UnchangedOr<T>
impl<T: ContainerElement> AnyCompatible for UnchangedOr<T>
Source§unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
unsafe fn copy_to_any_view(src: &Self, data: &mut TVMFFIAny)
Source§unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
unsafe fn move_to_any(src: Self, data: &mut TVMFFIAny)
unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
Source§unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
unsafe fn copy_from_any_view_after_check(data: &TVMFFIAny) -> Self
Source§unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
Source§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
Source§fn type_schema() -> String
fn type_schema() -> String
TypeTraits<T>::TypeSchema writes, which the type schemas of functions
and fields embed. Read moreSource§unsafe fn is_undefined(field: *const Self) -> bool
unsafe fn is_undefined(field: *const Self) -> bool
field, which holds a value of this type or all-zero bytes,
holds all-zero bytes that are no value of this type, as a null object
reference, a string of type index None or a zero device type: a field
that a creator left undefined for reflection to set, as C++ UnsafeInit
leaves a reference undefined (null). Unlike a C++ undefined reference,
it is no value; a nullable reference is Option<T>, whose None is a
defined value. Read more