Skip to main content

MaybeUndefined

Enum MaybeUndefined 

Source
pub enum MaybeUndefined<T> {
    Undefined,
    Null,
    Value(T),
}
Expand description

A three-state field value: undefined (omitted), null (explicit clear), or a concrete value.

See the module documentation for the rationale and wire-format mapping.

§Struct-context contract

The Undefined / Null distinction is preserved on the wire only when this value sits in a struct field carrying #[serde(default, skip_serializing_if = "MaybeUndefined::is_undefined")] — which is what codegen emits for every nullable input field. In any other context (serde_json::to_value(MaybeUndefined::<T>::Undefined), a bare value inside a Vec<MaybeUndefined<T>>, etc.) Undefined cannot be “omitted” — there’s no containing struct to omit it from — and serializes as JSON null, collapsing the distinction. Use this type only as a struct field paired with the skip predicate above.

§Derive bounds

The Eq and Hash impls are conditional on T: Eq + Hash. Types containing non-Eq scalars (notably f64) therefore can’t derive those traits transitively — this is expected and matches Option<T>.

Variants§

§

Undefined

Field is absent from the serialized output.

§

Null

Field is serialized as JSON null (clears the value on the server).

§

Value(T)

Field is serialized as the wrapped value.

Implementations§

Source§

impl<T> MaybeUndefined<T>

Source

pub fn is_undefined(&self) -> bool

Returns true if the value is MaybeUndefined::Undefined.

Codegen uses this as the skip_serializing_if predicate so Undefined fields are omitted from the serialized output entirely.

Trait Implementations§

Source§

impl<T: Clone> Clone for MaybeUndefined<T>

Source§

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

Returns a duplicate 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 MaybeUndefined<T>

Source§

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

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

impl<T> Default for MaybeUndefined<T>

Source§

fn default() -> Self

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

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

Maps the three JSON inputs a struct field can present as follows:

InputResult
field absent from JSONUndefined (via #[serde(default)])
field present with nullNull
field present with a value vValue(v)

Absent-field handling is driven by #[serde(default)] on the struct field, not by this impl — serde only calls deserialize when the key is present. Codegen emits that attribute on every nullable input field, which is what preserves the three-state distinction on round-trip.

Note the intentional asymmetry with From<Option<T>>: None → Undefined during construction (a missing CLI flag shouldn’t touch the server), but JSON null → Null during deserialization (the server did send null).

Source§

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

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

impl<T> From<Option<T>> for MaybeUndefined<T>

Lifts an Option<T> into the three-state world, collapsing None to Undefined.

This is the right default for constructing input values: a CLI flag that wasn’t passed (Option::None) means “leave the field unchanged”, so it maps to Undefined. If you instead want None to clear the field on the server, use MaybeUndefined::Null explicitly.

Note the intentional asymmetry with Deserialize: when round-tripping through JSON, an absent field deserializes to Undefined (via the #[serde(default)] on the field), while an explicit JSON null deserializes to Null. That matches GraphQL’s wire semantics. Option<T> doesn’t carry the “absent” vs “null” distinction, so From<Option<T>> can’t preserve it either.

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<T> for MaybeUndefined<T>

Source§

fn from(v: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for MaybeUndefined<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: PartialEq> PartialEq for MaybeUndefined<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Serialize> Serialize for MaybeUndefined<T>

Source§

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

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

impl<T: Eq> Eq for MaybeUndefined<T>

Source§

impl<T> StructuralPartialEq for MaybeUndefined<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for MaybeUndefined<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> 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<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> FieldCompatible<T> for T