Skip to main content

Patch

Enum Patch 

Source
pub enum Patch<T> {
    Missing,
    Null,
    Value(T),
}
Expand description

A field of a merge patch that may also be cleared: absent from the patch, set to null, or given a value.

With the serde feature, it deserializes null as Patch::Null and a value as Patch::Value; an absent field takes the default, Patch::Missing, so put #[serde(default)] on the struct (or the field). To document it with utoipa, give the field #[schema(value_type = Option<T>)]: a nullable T, as clients send it.

Variants§

§

Missing

Absent from the patch: the field is left unchanged.

§

Null

Set to null: the field is cleared.

§

Value(T)

Given a value: the field is replaced.

Implementations§

Source§

impl<T> Patch<T>

Source

pub const fn is_missing(&self) -> bool

Whether the field is absent from the patch.

Source

pub const fn is_null(&self) -> bool

Whether the field is set to null.

Source

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

The value given, if any (None when absent or null).

Source

pub const fn as_ref(&self) -> Patch<&T>

A reference to the value given, if any.

Source

pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Patch<U>

The patch with its value, if any, mapped by f.

Source

pub fn try_map<U, E>( self, f: impl FnOnce(T) -> Result<U, E>, ) -> Result<Patch<U>, E>

The patch with its value, if any, mapped by the fallible f (e.g. parsing a value object), or f’s error.

§Errors

Returns f’s error.

Trait Implementations§

Source§

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

Source§

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

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 for Patch<T>
where T: Copy,

Source§

impl<T> Debug for Patch<T>
where T: Debug,

Source§

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

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

impl<T> Default for Patch<T>

Source§

fn default() -> Patch<T>

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

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

null is Patch::Null, a value Patch::Value; an absent field is the default, Patch::Missing, through #[serde(default)].

Source§

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

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

impl<T> Eq for Patch<T>
where T: Eq,

Source§

impl<T> Hash for Patch<T>
where T: Hash,

Source§

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

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> JsonSchema for Patch<T>
where T: JsonSchema,

Documented as a nullable T, as clients send it: an absent field is not in the request at all.

Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

impl<T> PartialEq for Patch<T>
where T: PartialEq,

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl<P, F> PatchField<Option<F>> for Patch<P>
where P: Into<F>,

Source§

fn apply_to(self, field: &mut Option<F>)

Apply the patch’s field to the model’s field.
Source§

impl<T> PatchKind for Patch<T>

Source§

const NULLABLE: bool = true

Whether a field of this kind may be set to null.
Source§

fn is_null(&self) -> bool

Whether this field is set to null.
Source§

impl<T> Serialize for Patch<T>
where T: Serialize,

A value as itself, null (and an absent field, which a struct skips with #[serde(skip_serializing_if = "Patch::is_missing")]) as null.

Source§

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

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

impl<T> StructuralPartialEq for Patch<T>
where T: PartialEq,

Source§

impl<T> ValidateRange<T> for Patch<T>
where T: ValidateRange<T>,

validator’s range rule checks a given value, and passes an absent field or a null (which ValidateNonNullable checks), as it does an Option. Delegates to the value’s own check, so every type validator ranges over works.

Source§

fn greater_than(&self, max: T) -> Option<bool>

Source§

fn less_than(&self, min: T) -> Option<bool>

Source§

fn validate_range( &self, min: Option<T>, max: Option<T>, exclusive_min: Option<T>, exclusive_max: Option<T>, ) -> bool

Auto Trait Implementations§

§

impl<T> Forget for Patch<T>

§

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

§

impl<T> Move for Patch<T>

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Patch<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> 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 = !

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