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
sourceimpl<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
sourceimpl<S, T> FromInputValue<S> for Nullable<T> where
T: FromInputValue<S>,
S: ScalarValue,
impl<S, T> FromInputValue<S> for Nullable<T> where
T: FromInputValue<S>,
S: ScalarValue,
sourcefn from_input_value(v: &InputValue<S>) -> Option<Nullable<T>>
fn from_input_value(v: &InputValue<S>) -> Option<Nullable<T>>
Performs the conversion.
sourcefn from_implicit_null() -> Self
fn from_implicit_null() -> Self
Performs the conversion from an absent value (e.g. to distinguish between implicit and
explicit null). The default implementation just uses from_input_value
as if an explicit
null were provided. This conversion must not fail. Read more
sourceimpl<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,
sourceimpl<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>,
type Context = <T as GraphQLValue<S>>::Context
type Context = <T as GraphQLValue<S>>::Context
Context type for this GraphQLValue
. Read more
type TypeInfo = <T as GraphQLValue<S>>::TypeInfo
type TypeInfo = <T as GraphQLValue<S>>::TypeInfo
Type that may carry additional schema information for this GraphQLValue
. Read more
sourcefn type_name(&self, _: &Self::TypeInfo) -> Option<&'static str>
fn type_name(&self, _: &Self::TypeInfo) -> Option<&'static str>
Returns name of the GraphQLType
exposed by this GraphQLValue
. Read more
sourcefn 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>
Resolves the provided selection_set
against this GraphQLValue
. Read more
sourcefn 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>
Resolves the value of a single field on this GraphQLValue
. Read more
sourcefn 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>
Resolves this GraphQLValue
(being an interface or an union) into a concrete
downstream object type. Read more
sourcefn concrete_type_name(
&self,
context: &Self::Context,
info: &Self::TypeInfo
) -> String
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
sourceimpl<S, T> GraphQLValueAsync<S> for Nullable<T> where
T: GraphQLValueAsync<S>,
T::TypeInfo: Sync,
T::Context: Sync,
S: ScalarValue + Send + Sync,
impl<S, T> GraphQLValueAsync<S> for Nullable<T> where
T: GraphQLValueAsync<S>,
T::TypeInfo: Sync,
T::Context: Sync,
S: ScalarValue + Send + Sync,
sourcefn 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>>
Resolves the provided selection_set
against this GraphQLValueAsync
. Read more
sourcefn 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>>
Resolves the value of a single field on this GraphQLValueAsync
. Read more
sourcefn 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>>
Resolves this GraphQLValueAsync
(being an interface or an union) into a
concrete downstream object type. Read more
sourceimpl<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,
sourceimpl<T: Ord> Ord for Nullable<T>
impl<T: Ord> Ord for Nullable<T>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T: PartialOrd> PartialOrd<Nullable<T>> for Nullable<T>
impl<T: PartialOrd> PartialOrd<Nullable<T>> for Nullable<T>
sourcefn partial_cmp(&self, other: &Nullable<T>) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
sourceimpl<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,
sourcefn to_input_value(&self) -> InputValue<S>
fn to_input_value(&self) -> InputValue<S>
Performs the conversion.
impl<T: Copy> Copy for Nullable<T>
impl<T: Eq> Eq for Nullable<T>
impl<T> StructuralEq for Nullable<T>
impl<T> StructuralPartialEq for Nullable<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.