[−][src]Enum japi::Optional
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
The key was present in the document and had a value
The key was not present
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]
F: FnOnce(T) -> U,
Map the value if it was present
pub fn map_null<F>(self, f: F) -> Option<T> where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
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]
pub fn unwrap_or_else_null<F>(self, null: F) -> T where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
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]
T: DeserializeOwned,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
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]
T: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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,
T: RefUnwindSafe,
impl<T> Send for Optional<T> where
T: Send,
T: Send,
impl<T> Sync for Optional<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Optional<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Optional<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,