[][src]Enum japi::Optional

pub enum Optional<T> {
    Present(T),
    NotPresent,
    Null,
}

Represents a value that can either exist, not exist, or be null

This is a helper object for building Attributes. When including it in an attribute use #[serde(skip_serializing_if = "Optional::is_not_present", default)].

Variants

Present(T)

The key was present in the document and had a value

NotPresent

The key was not present

Null

The key was present and was null

Methods

impl<T> Optional<T>[src]

pub fn is_present(&self) -> bool[src]

The key was present and had a value

pub fn is_not_present(&self) -> bool[src]

The key was not present

pub fn is_null(&self) -> bool[src]

The key was present and was null

pub fn map<U, F>(self, f: F) -> Optional<U> where
    F: FnOnce(T) -> U, 
[src]

Map the value if it was present

pub fn map_null<F>(self, f: F) -> Option<T> where
    F: FnOnce() -> T, 
[src]

Maps Present to Some, calls f is Null and maps the result to Some, maps NotPresent to None

pub fn as_option(self) -> Option<T>[src]

Converts to Some if Present, otherwise converts to None

pub fn as_ref(&self) -> Optional<&T>[src]

Converts from &Optional<T> to Optional<&T>

pub fn as_mut(&mut self) -> Optional<&mut T>[src]

Converts from &mut Optional<T> to Optional<&mut T>

pub fn expect(self, msg: &str) -> T[src]

Unwraps an Optional, yeilding the content of a Present

Panics

Panics if the value is not a Present with a custom panic message provided by msg

pub fn unwrap(self) -> T[src]

Move the value v out of the Optional<T> if it is Present(v).

Panics

Panics if the value is not a Present

pub fn unwrap_or_null(self, null: T) -> T[src]

Unwraps if Present, returns null if Null

Panics

Panics if the value is NotPresent

pub fn unwrap_or_else_null<F>(self, null: F) -> T where
    F: FnOnce() -> T, 
[src]

Unwraps if Present, calls null and returns the result if Null

Panics

Panics if the value is NotPresent

Trait Implementations

impl<T: Clone> Clone for Optional<T>[src]

impl<T: Debug> Debug for Optional<T>[src]

impl<T> Default for Optional<T>[src]

Defaults to NotPresent

impl<'de, T> Deserialize<'de> for Optional<T> where
    T: DeserializeOwned
[src]

impl<T: Eq> Eq for Optional<T>[src]

impl<T> From<Option<T>> for Optional<T>[src]

Maps None to NotPresent

impl<T: PartialEq> PartialEq<Optional<T>> for Optional<T>[src]

impl<T> Serialize for Optional<T> where
    T: Serialize
[src]

impl<T> StructuralEq for Optional<T>[src]

impl<T> StructuralPartialEq for Optional<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Optional<T> where
    T: RefUnwindSafe

impl<T> Send for Optional<T> where
    T: Send

impl<T> Sync for Optional<T> where
    T: Sync

impl<T> Unpin for Optional<T> where
    T: Unpin

impl<T> UnwindSafe for Optional<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.