pub struct Optional<T: OptionalCompatible> { /* private fields */ }Expand description
An optional value that is not an object, stored in place as one 16-byte
cell holding the value or None. See the module docs.
Implementations§
Source§impl<T: OptionalCompatible> Optional<T>
impl<T: OptionalCompatible> Optional<T>
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Takes the value out, without cloning it.
Source§impl<T: OptionalCompatible + RefFromAnyUnchecked> Optional<T>
impl<T: OptionalCompatible + RefFromAnyUnchecked> Optional<T>
Sourcepub fn as_ref(&self) -> Option<&T>
pub fn as_ref(&self) -> Option<&T>
Borrow the value in place, like Option::as_ref.
Available for values the cell stores as themselves, such as String,
i64 and f64; use get for the others.
§Returns
The borrowed value, or None when empty.
use tvm_ffi::Optional;
let value = Optional::some(7_i64);
assert_eq!(value.as_ref(), Some(&7));
assert_eq!(Optional::<i64>::none().as_ref(), None);Trait Implementations§
Source§impl<T: OptionalCompatible> AnyCompatible for Optional<T>
impl<T: OptionalCompatible> AnyCompatible for Optional<T>
Source§fn type_str() -> String
fn type_str() -> String
The type name in conversion errors and type schemas, such as
int,
ffi.String or Array<int>.Source§fn type_schema() -> String
fn type_schema() -> String
The type schema of the type: the JSON object that describes it, which
the type schemas of functions and fields embed. Read more
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)
Source§unsafe fn check_any_strict(data: &TVMFFIAny) -> bool
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
Copy a
Self out of a cell that holds one, retaining any object. Read moreSource§unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
unsafe fn move_from_any_after_check(data: &mut TVMFFIAny) -> Self
Move a
Self out of an owning cell that holds one. Read moreSource§unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
unsafe fn try_cast_from_any_view(data: &TVMFFIAny) -> Result<Self, ()>
Convert
data into a Self by the FFI rules, such as an integer into a
float; Err if it does not convert. Read moreSource§unsafe fn is_undefined(field: *const Self) -> bool
unsafe fn is_undefined(field: *const Self) -> bool
Whether
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. An undefined field
is no value; a nullable reference is Option<T>, whose None is a
defined value. Read moreSource§fn get_mismatch_type_info(data: &TVMFFIAny) -> String
fn get_mismatch_type_info(data: &TVMFFIAny) -> String
The name of the mismatched value
data in conversion errors; by
default its runtime type key.Source§impl<T: OptionalCompatible> Clone for Optional<T>
impl<T: OptionalCompatible> Clone for Optional<T>
Source§impl<T: OptionalCompatible> Default for Optional<T>
impl<T: OptionalCompatible> Default for Optional<T>
impl<T: OptionalCompatible + Eq> Eq for Optional<T>
impl<T: OptionalCompatible + Send + Sync> Send for Optional<T>
impl<T: OptionalCompatible + Send + Sync> Sync for Optional<T>
Auto Trait Implementations§
impl<T> Freeze for Optional<T>
impl<T> RefUnwindSafe for Optional<T>where
T: RefUnwindSafe,
impl<T> Unpin for Optional<T>where
T: Unpin,
impl<T> UnsafeUnpin for Optional<T>
impl<T> UnwindSafe for Optional<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more