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

Construct a JsOption from a regular Option.

None will be converted to to Null.

Construct a JsOption from a regular Option.

None will be converted to Undefined.

Convert a JsOption to Option.

Convert a JsOption<T> to Option<Option<T>>.

Null is represented as Some(None) while Undefined is represented as None.

Returns true if the JsOption contains a value.

Returns true if the JsOption is Null.

Returns true if the JsOption is Undefined.

Returns the contained Some value, consuming the self value.

Panics

Panics if the self value equals Null or Undefined.

Returns the contained Some value or a provided default.

Returns the contained Some value computes is from a closure.

Maps a JsOption<T> to JsOption<U> by applying a function to a contained value.

Converts from &Option<T> to Option<&T>.

Converts from &mut Option<T> to Option<&mut T>.

Returns the contained Some value or a default.

Converts from &JsOption<T> to JsOption<&T::Target>.

Converts from &mut JsOption<T> to JsOption<&mut T::Target>.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the default value, JsOption::Undefined.

Deserialize a JsOption.

This implementation will never return Undefined. You need to use #[serde(default)] to get Undefined when the field is not present.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize a JsOption.

Serialization will fail for JsOption::Undefined. You need to use #[skip_serializing_if = "JsOption::is_undefined"] to stop the field from being serialized altogether.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.