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§
Implementations§
Source§impl<T> Nullable<T>
impl<T> Nullable<T>
Sourcepub fn is_explicit_null(&self) -> bool
pub fn is_explicit_null(&self) -> bool
Returns true
if the nullable is a ExplicitNull
value.
Sourcepub fn is_implicit_null(&self) -> bool
pub fn is_implicit_null(&self) -> bool
Returns true
if the nullable is a ImplicitNull
value.
Sourcepub fn as_mut(&mut self) -> Nullable<&mut T>
pub fn as_mut(&mut self) -> Nullable<&mut T>
Converts from &mut Nullable<T>
to Nullable<&mut T>
.
Sourcepub fn expect(self, msg: &str) -> T
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
.
Sourcepub fn unwrap_or(self, default: T) -> T
pub fn unwrap_or(self, default: T) -> T
Returns the contained Some
value or a provided default.
Sourcepub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
Returns the contained Some
value or computes it from a closure.
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Nullable<U>
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.
Sourcepub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U
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).
Sourcepub fn map_or_else<U, D: FnOnce() -> U, F: FnOnce(T) -> U>(
self,
default: D,
f: F,
) -> U
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).
Sourcepub fn ok_or<E>(self, err: E) -> Result<T, E>
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)
.
Sourcepub fn ok_or_else<E, F: FnOnce() -> E>(self, err: F) -> Result<T, E>
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())
.
Sourcepub fn or(self, b: Self) -> Self
pub fn or(self, b: Self) -> Self
Returns the nullable if it contains a value, otherwise returns b
.
Sourcepub fn or_else<F: FnOnce() -> Nullable<T>>(self, f: F) -> Nullable<T>
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.
Trait Implementations§
Source§impl<S, T: FromInputValue<S>> FromInputValue<S> for Nullable<T>
impl<S, T: FromInputValue<S>> FromInputValue<S> for Nullable<T>
Source§fn from_input_value(v: &InputValue<S>) -> Result<Self, Self::Error>
fn from_input_value(v: &InputValue<S>) -> Result<Self, Self::Error>
Source§impl<S, T> GraphQLType<S> for Nullable<T>where
T: GraphQLType<S>,
S: ScalarValue,
impl<S, T> GraphQLType<S> for Nullable<T>where
T: GraphQLType<S>,
S: ScalarValue,
Source§impl<S, T> GraphQLValue<S> for Nullable<T>where
S: ScalarValue,
T: GraphQLValue<S>,
impl<S, T> GraphQLValue<S> for Nullable<T>where
S: ScalarValue,
T: GraphQLValue<S>,
Source§type Context = <T as GraphQLValue<S>>::Context
type Context = <T as GraphQLValue<S>>::Context
GraphQLValue
. Read moreSource§type TypeInfo = <T as GraphQLValue<S>>::TypeInfo
type TypeInfo = <T as GraphQLValue<S>>::TypeInfo
GraphQLValue
. Read moreSource§fn resolve(
&self,
info: &Self::TypeInfo,
_: Option<&[Selection<'_, S>]>,
executor: &Executor<'_, '_, Self::Context, S>,
) -> ExecutionResult<S>
fn resolve( &self, info: &Self::TypeInfo, _: Option<&[Selection<'_, S>]>, executor: &Executor<'_, '_, Self::Context, S>, ) -> ExecutionResult<S>
Source§fn resolve_field(
&self,
_info: &Self::TypeInfo,
_field_name: &str,
_arguments: &Arguments<'_, S>,
_executor: &Executor<'_, '_, Self::Context, S>,
) -> ExecutionResult<S>
fn resolve_field( &self, _info: &Self::TypeInfo, _field_name: &str, _arguments: &Arguments<'_, S>, _executor: &Executor<'_, '_, Self::Context, S>, ) -> ExecutionResult<S>
GraphQLValue
. Read moreSource§fn resolve_into_type(
&self,
info: &Self::TypeInfo,
type_name: &str,
selection_set: Option<&[Selection<'_, S>]>,
executor: &Executor<'_, '_, Self::Context, S>,
) -> ExecutionResult<S>
fn resolve_into_type( &self, info: &Self::TypeInfo, type_name: &str, selection_set: Option<&[Selection<'_, S>]>, executor: &Executor<'_, '_, Self::Context, S>, ) -> ExecutionResult<S>
GraphQLValue
(being an interface or an union) into a concrete
downstream object type. Read moreSource§fn concrete_type_name(
&self,
context: &Self::Context,
info: &Self::TypeInfo,
) -> String
fn concrete_type_name( &self, context: &Self::Context, info: &Self::TypeInfo, ) -> String
GraphQLType
name for this GraphQLValue
being an interface,
an union or an object. Read moreSource§impl<S, T> GraphQLValueAsync<S> for Nullable<T>
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>>
fn resolve_async<'a>( &'a self, info: &'a Self::TypeInfo, _: Option<&'a [Selection<'_, S>]>, executor: &'a Executor<'_, '_, Self::Context, S>, ) -> BoxFuture<'a, ExecutionResult<S>>
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>>
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>>
GraphQLValueAsync
. Read moreSource§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>>
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>>
GraphQLValueAsync
(being an interface or an union) into a
concrete downstream object type. Read moreSource§impl<S, T> IsInputType<S> for Nullable<T>where
T: IsInputType<S>,
S: ScalarValue,
impl<S, T> IsInputType<S> for Nullable<T>where
T: IsInputType<S>,
S: ScalarValue,
Source§impl<T: Ord> Ord for Nullable<T>
impl<T: Ord> Ord for Nullable<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd> PartialOrd for Nullable<T>
impl<T: PartialOrd> PartialOrd for Nullable<T>
Source§impl<S, T> ToInputValue<S> for Nullable<T>where
T: ToInputValue<S>,
S: ScalarValue,
impl<S, T> ToInputValue<S> for Nullable<T>where
T: ToInputValue<S>,
S: ScalarValue,
Source§fn to_input_value(&self) -> InputValue<S>
fn to_input_value(&self) -> InputValue<S>
impl<T: Copy> Copy for Nullable<T>
impl<T: Eq> Eq for Nullable<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.