pub enum JsOption<T> {
Some(T),
Null,
Undefined,
}
Expand description
An Option
-like type with two data-less variants in addition to Some
:
Null
and Undefined
.
Variants
Some(T)
Some value T
Null
Explicit absence of a value
Undefined
Implicit absence of a value
Implementations
sourceimpl<T> JsOption<T>
impl<T> JsOption<T>
sourcepub fn from_option(opt: Option<T>) -> Self
pub fn from_option(opt: Option<T>) -> Self
Construct a JsOption
from a regular Option
.
None
will be converted to to Null
.
sourcepub fn from_implicit_option(opt: Option<T>) -> Self
pub fn from_implicit_option(opt: Option<T>) -> Self
Construct a JsOption
from a regular Option
.
None
will be converted to Undefined
.
sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Convert a JsOption
to Option
.
sourcepub fn into_nested_option(self) -> Option<Option<T>>
pub fn into_nested_option(self) -> Option<Option<T>>
Convert a JsOption<T>
to Option<Option<T>>
.
Null
is represented as Some(None)
while Undefined
is represented
as None
.
sourcepub const fn is_undefined(&self) -> bool
pub const fn is_undefined(&self) -> bool
Returns true
if the JsOption
is Undefined
.
sourcepub fn unwrap(self) -> T
pub fn unwrap(self) -> T
Returns the contained Some
value, consuming the self
value.
Panics
Panics if the self value equals Null
or Undefined
.
sourcepub fn unwrap_or(self, default: T) -> T
pub fn unwrap_or(self, default: T) -> T
Returns the contained Some
value or a provided default.
sourcepub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
Returns the contained Some
value computes is from a closure.
sourceimpl<T: Default> JsOption<T>
impl<T: Default> JsOption<T>
sourcepub fn unwrap_or_default(self) -> T
pub fn unwrap_or_default(self) -> T
Returns the contained Some
value or a default.
Trait Implementations
sourceimpl<'de, T> Deserialize<'de> for JsOption<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for JsOption<T> where
T: Deserialize<'de>,
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize a JsOption
.
This implementation will never return Undefined
. You need to use
#[serde(default)]
to get Undefined
when the field is not present.
sourceimpl<T: Ord> Ord for JsOption<T>
impl<T: Ord> Ord for JsOption<T>
sourceimpl<T: PartialOrd> PartialOrd<JsOption<T>> for JsOption<T>
impl<T: PartialOrd> PartialOrd<JsOption<T>> for JsOption<T>
sourcefn partial_cmp(&self, other: &JsOption<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &JsOption<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T: Copy> Copy for JsOption<T>
impl<T: Eq> Eq for JsOption<T>
impl<T> StructuralEq for JsOption<T>
impl<T> StructuralPartialEq for JsOption<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for JsOption<T> where
T: RefUnwindSafe,
impl<T> Send for JsOption<T> where
T: Send,
impl<T> Sync for JsOption<T> where
T: Sync,
impl<T> Unpin for JsOption<T> where
T: Unpin,
impl<T> UnwindSafe for JsOption<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more