Enum juniper::Nullable

source ·
pub enum Nullable<T> {
    ImplicitNull,
    ExplicitNull,
    Some(T),
}
Expand description

Nullable can be used in situations where you need to distinguish between an implicitly and explicitly null input value.

The GraphQL spec states that these two field calls are similar, but are not identical:

{
  field(arg: null)
  field
}

The first has explicitly provided null to the argument “arg”, while the second has implicitly not provided a value to the argument “arg”. These two forms may be interpreted differently. For example, a mutation representing deleting a field vs not altering a field, respectively.

In cases where you do not need to be able to distinguish between the two types of null, you should simply use Option<T>.

Variants§

§

ImplicitNull

No value

§

ExplicitNull

No value, explicitly specified to be null

§

Some(T)

Some value T

Implementations§

source§

impl<T> Nullable<T>

source

pub fn is_explicit_null(&self) -> bool

Returns true if the nullable is a ExplicitNull value.

source

pub fn is_implicit_null(&self) -> bool

Returns true if the nullable is a ImplicitNull value.

source

pub fn is_some(&self) -> bool

Returns true if the nullable is a Some value.

source

pub fn is_null(&self) -> bool

Returns true if the nullable is not a Some value.

source

pub fn as_mut(&mut self) -> Nullable<&mut T>

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

source

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

Returns the contained Some value, consuming the self value.

§Panics

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

source

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

Returns the contained Some value or a provided default.

source

pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T

Returns the contained Some value or computes it from a closure.

source

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

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

source

pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U

Applies a function to the contained value (if any), or returns the provided default (if not).

source

pub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>( self, default: D, f: F ) -> U

Applies a function to the contained value (if any), or computes a default (if not).

source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Transforms the Nullable<T> into a Result<T, E>, mapping Some(v) to Ok(v) and ImplicitNull or ExplicitNull to Err(err).

source

pub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E>

Transforms the Nullable<T> into a Result<T, E>, mapping Some(v) to Ok(v) and ImplicitNull or ExplicitNull to Err(err()).

source

pub fn or(self, b: Self) -> Self

Returns the nullable if it contains a value, otherwise returns b.

source

pub fn or_else<F: FnOnce() -> Nullable<T>>(self, f: F) -> Nullable<T>

Returns the nullable if it contains a value, otherwise calls f and returns the result.

source

pub fn replace(&mut self, value: T) -> Self

Replaces the actual value in the nullable by the value given in parameter, returning the old value if present, leaving a Some in its place without deinitializing either one.

source

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

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

source

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

Converts from Nullable<T> to Option<Option<T>>, mapping Some(v) to Some(Some(v)), ExplicitNull to Some(None), and ImplicitNull to None.

source§

impl<T: Copy> Nullable<&T>

source

pub fn copied(self) -> Nullable<T>

Maps a Nullable<&T> to a Nullable<T> by copying the contents of the nullable.

source§

impl<T: Copy> Nullable<&mut T>

source

pub fn copied(self) -> Nullable<T>

Maps a Nullable<&mut T> to a Nullable<T> by copying the contents of the nullable.

source§

impl<T: Clone> Nullable<&T>

source

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

Maps a Nullable<&T> to a Nullable<T> by cloning the contents of the nullable.

source§

impl<T: Clone> Nullable<&mut T>

source

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

Maps a Nullable<&mut T> to a Nullable<T> by cloning the contents of the nullable.

Trait Implementations§

source§

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

source§

fn clone(&self) -> Nullable<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
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<T> Default for Nullable<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<S, T: FromInputValue<S>> FromInputValue<S> for Nullable<T>

§

type Error = <T as FromInputValue<S>>::Error

Type of this conversion error. Read more
source§

fn from_input_value(v: &InputValue<S>) -> Result<Self, Self::Error>

Performs the conversion.
source§

fn from_implicit_null() -> Result<Self, Self::Error>

Performs the conversion from an absent value (e.g. to distinguish between implicit and explicit null). Read more
source§

impl<S, T> GraphQLType<S> for Nullable<T>
where T: GraphQLType<S>, S: ScalarValue,

source§

fn name(_: &Self::TypeInfo) -> Option<&'static str>

Returns name of this GraphQLType to expose. Read more
source§

fn meta<'r>( info: &Self::TypeInfo, registry: &mut Registry<'r, S> ) -> MetaType<'r, S>
where S: 'r,

Returns MetaType representing this GraphQLType.
source§

impl<S, T> GraphQLValue<S> for Nullable<T>
where S: ScalarValue, T: GraphQLValue<S>,

§

type Context = <T as GraphQLValue<S>>::Context

Context type for this GraphQLValue. Read more
§

type TypeInfo = <T as GraphQLValue<S>>::TypeInfo

Type that may carry additional schema information for this GraphQLValue. Read more
source§

fn type_name(&self, _: &Self::TypeInfo) -> Option<&'static str>

Returns name of the GraphQLType exposed by this GraphQLValue. Read more
source§

fn resolve( &self, info: &Self::TypeInfo, _: Option<&[Selection<'_, S>]>, executor: &Executor<'_, '_, Self::Context, S> ) -> ExecutionResult<S>

Resolves the provided selection_set against this GraphQLValue. Read more
source§

fn resolve_field( &self, _info: &Self::TypeInfo, _field_name: &str, _arguments: &Arguments<'_, S>, _executor: &Executor<'_, '_, Self::Context, S> ) -> ExecutionResult<S>

Resolves the value of a single field on this GraphQLValue. Read more
source§

fn resolve_into_type( &self, info: &Self::TypeInfo, type_name: &str, selection_set: Option<&[Selection<'_, S>]>, executor: &Executor<'_, '_, Self::Context, S> ) -> ExecutionResult<S>

Resolves this GraphQLValue (being an interface or an union) into a concrete downstream object type. Read more
source§

fn concrete_type_name( &self, context: &Self::Context, info: &Self::TypeInfo ) -> String

Returns the concrete GraphQLType name for this GraphQLValue being an interface, an union or an object. Read more
source§

impl<S, T> GraphQLValueAsync<S> for Nullable<T>

source§

fn resolve_async<'a>( &'a self, info: &'a Self::TypeInfo, _: Option<&'a [Selection<'_, S>]>, executor: &'a Executor<'_, '_, Self::Context, S> ) -> BoxFuture<'a, ExecutionResult<S>>

Resolves the provided selection_set against this GraphQLValueAsync. Read more
source§

fn resolve_field_async<'a>( &'a self, _info: &'a Self::TypeInfo, _field_name: &'a str, _arguments: &'a Arguments<'_, S>, _executor: &'a Executor<'_, '_, Self::Context, S> ) -> BoxFuture<'a, ExecutionResult<S>>

Resolves the value of a single field on this GraphQLValueAsync. Read more
source§

fn resolve_into_type_async<'a>( &'a self, info: &'a Self::TypeInfo, type_name: &str, selection_set: Option<&'a [Selection<'a, S>]>, executor: &'a Executor<'a, 'a, Self::Context, S> ) -> BoxFuture<'a, ExecutionResult<S>>

Resolves this GraphQLValueAsync (being an interface or an union) into a concrete downstream object type. Read more
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<S, T> IsInputType<S> for Nullable<T>
where T: IsInputType<S>, S: ScalarValue,

source§

fn mark()

An arbitrary function without meaning. Read more
source§

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

source§

fn cmp(&self, other: &Nullable<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · source§

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

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

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

source§

fn eq(&self, other: &Nullable<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

source§

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

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

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 · source§

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
1.0.0 · source§

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

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

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

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

impl<S, T> ToInputValue<S> for Nullable<T>
where T: ToInputValue<S>, S: ScalarValue,

source§

fn to_input_value(&self) -> InputValue<S>

Performs the conversion.
source§

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

source§

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

source§

impl<T> StructuralPartialEq for Nullable<T>

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> 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<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> Conv for T

source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
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<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<T> FmtForward for T

source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pipe for T
where T: ?Sized,

source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Tap for T

source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
source§

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

§

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> TryConv for T

source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V