Skip to main content

Nullable

Enum Nullable 

Source
pub enum Nullable<T> {
    Null,
    Some(T),
}
Expand description

Value that can be null.

Option is used throughout this crate for entries that may or may not be present. A JSON-LD entry can also be present with the explicit value null, which is meaningful: it unsets whatever the surrounding context inherited. Hence this separate type, so that Option<Nullable<T>> can tell an absent entry from an entry set to null.

Variants§

§

Null

The null value.

§

Some(T)

Any other value.

Implementations§

Source§

impl<T> Nullable<T>

Source

pub fn is_null(&self) -> bool

Checks if the value is null.

Source

pub fn is_some(&self) -> bool

Checks if the value is not null.

Source

pub fn try_unwrap(self) -> Result<T, NullError>

Returns the inner value, or NullError if null.

§Errors

Returns an error when the value is null.

Source

pub fn as_ref(&self) -> Nullable<&T>

Converts &Nullable<T> into Nullable<&T>.

Source

pub fn as_deref(&self) -> Nullable<&T::Target>
where T: Deref,

Converts &Nullable<T> into Nullable<&T::Target> by dereferencing the inner value.

Source

pub fn option(self) -> Option<T>

Converts this value into an Option, mapping null to None.

Source

pub fn map<F, U>(self, f: F) -> Nullable<U>
where F: FnOnce(T) -> U,

Maps the inner value with the given function, keeping null as null.

Source

pub fn cast<U>(self) -> Nullable<U>
where T: Into<U>,

Converts the contained value, keeping null as null.

Source

pub fn unwrap_or(self, default: T) -> T

Returns the contained value, or default if it is null.

Source

pub fn unwrap_or_default(self) -> T
where T: Default,

Returns the contained value, or the default one if it is null.

Source§

impl<T: Clone> Nullable<&T>

Source

pub fn cloned(&self) -> Nullable<T>

Clones the referenced inner value.

Source§

impl<T> Nullable<T>

Source

pub fn optional<'de, D>(deserializer: D) -> Result<Option<Self>, D::Error>
where T: Deserialize<'de>, D: Deserializer<'de>,

Available on crate feature serde only.

Deserializes a Nullable<T> and wraps it in Some.

Meant as the deserialize_with of an Option<Nullable<T>> field that also carries #[serde(default)]: an absent entry then yields None, while an entry present with the value null yields Some(Nullable::Null). Serde’s own handling of Option would collapse both cases to None.

§Errors

Returns the deserializer’s error when the value is neither absent, null, nor a valid T.

Trait Implementations§

Source§

impl<T: Clone> Clone for Nullable<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for Nullable<T>

Source§

impl<T: Debug> Debug for Nullable<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, T: Deserialize<'de>> Deserialize<'de> for Nullable<T>

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Display> Display for Nullable<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: DisplayWithContext<V>, V> DisplayWithContext<V> for Nullable<T>

Source§

fn fmt_with(&self, vocabulary: &V, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Eq> Eq for Nullable<T>

Source§

impl<'a> From<Nullable<&'a TermDefinition>> for ExpandedRef<'a>

Source§

fn from(value: Nullable<&'a TermDefinition>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Nullable<T>

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Nullable<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Nullable<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T: IntoJson> IntoJson for Nullable<T>

Source§

fn into_json(self) -> Value

Converts this value into JSON.
Source§

impl<T: Ord> Ord for Nullable<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<T: PartialEq> PartialEq for Nullable<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialOrd> PartialOrd for Nullable<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PrecomputeSize for Nullable<&Vocab>

Source§

fn pre_compute_size(&self, options: &Options, sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<&TermDefinition>

Source§

fn pre_compute_size(&self, options: &Options, sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<&Id>

Source§

fn pre_compute_size(&self, options: &Options, sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<&Type>

Source§

fn pre_compute_size(&self, options: &Options, sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<&Container>

Source§

fn pre_compute_size(&self, options: &Options, sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<&IriRefBuf>

Source§

fn pre_compute_size(&self, _options: &Options, _sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<IriRefBuf>

Source§

fn pre_compute_size(&self, _options: &Options, _sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<bool>

Source§

fn pre_compute_size(&self, options: &Options, sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<&LenientLangTagBuf>

Source§

fn pre_compute_size(&self, _options: &Options, _sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl PrecomputeSize for Nullable<Direction>

Source§

fn pre_compute_size(&self, _options: &Options, _sizes: &mut Vec<Size>) -> Size

Computes the printed size of this value, appending the size of each nested array and object to sizes.
Source§

impl Print for Nullable<&Vocab>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<&Id>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<&Type>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<&IriRefBuf>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, _options: &Options, _indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<IriRefBuf>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, _options: &Options, _indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<bool>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<&LenientLangTagBuf>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, _options: &Options, _indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl Print for Nullable<Direction>

Source§

fn fmt_with( &self, f: &mut Formatter<'_>, _options: &Options, _indent: usize, ) -> Result

Writes the value to f with the given options, starting at the given indentation level. Read more
Source§

fn pretty_print(&self) -> Printed<'_, Self>

Print the value with Options::pretty options.
Source§

fn compact_print(&self) -> Printed<'_, Self>

Print the value with Options::compact options.
Source§

fn inline_print(&self) -> Printed<'_, Self>

Print the value with Options::inline options.
Source§

fn print_with(&self, options: Options) -> Printed<'_, Self>

Print the value with the given options.
Source§

impl PrintWithSize for Nullable<&TermDefinition>

Source§

fn fmt_with_size( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, sizes: &[Size], index: &mut usize, ) -> Result

Writes the value to f, taking its layout from sizes[*index]. Read more
Source§

impl PrintWithSize for Nullable<&Container>

Source§

fn fmt_with_size( &self, f: &mut Formatter<'_>, options: &Options, indent: usize, sizes: &[Size], index: &mut usize, ) -> Result

Writes the value to f, taking its layout from sizes[*index]. Read more
Source§

impl<T: Serialize> Serialize for Nullable<T>

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Nullable<T>

Source§

impl<T: TryFromJson> TryFromJson for Nullable<T>

Source§

type Error = <T as TryFromJson>::Error

Error raised when the JSON value does not describe a valid Self.
Source§

fn try_from_json(value: &Value) -> Result<Self, Self::Error>

Builds a value of this type from the given JSON value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Nullable<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Nullable<T>
where T: RefUnwindSafe,

§

impl<T> Send for Nullable<T>
where T: Send,

§

impl<T> Sync for Nullable<T>
where T: Sync,

§

impl<T> Unpin for Nullable<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Nullable<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Nullable<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> BorrowUnordered for T

Source§

fn as_unordered(&self) -> &Unordered<T>

Views this value as an Unordered reference.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if self is equivalent to key.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, C> FromWithContext<T, C> for T

Source§

fn from_with(value: T, _context: &C) -> T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

Source§

fn into_with(self, context: &C) -> U

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

Source§

type Error = !

Source§

fn try_from_with( value: U, context: &C, ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

type Error = <U as TryFromWithContext<T, C>>::Error

Source§

fn try_into_with( self, context: &C, ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

Source§

impl<T> WithContext for T
where T: ?Sized,

Source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

Source§

fn into_with<C>(self, context: C) -> Contextual<T, C>
where T: Sized,