pub enum Change<T> {
Unchanged,
Set(T),
}Expand description
A field of a partial-update (PATCH) body: absent, or a new value.
Mark the field #[serde(default)]: an absent field is
Unchanged, a present one is Set
with the value T reads from the input. null is therefore a value:
Change<Option<T>> holds Set(None) for it (clear the column), while
for a T that rejects null (String, numbers, …) the body fails
validation. Validation and the schema are T’s.
use serde::Deserialize;
use siderite_validation::Change;
#[derive(Deserialize)]
struct Patch {
#[serde(default)]
note: Change<Option<String>>,
}
let absent: Patch = serde_json::from_str("{}").unwrap();
assert_eq!(absent.note, Change::Unchanged);
let cleared: Patch = serde_json::from_str(r#"{"note":null}"#).unwrap();
assert_eq!(cleared.note, Change::Set(None));Variants§
Unchanged
The field was absent: keep the current value.
Set(T)
The field was present: the new value.
Implementations§
Trait Implementations§
impl<T: Copy> Copy for Change<T>
Source§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Change<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Change<T>
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl<T: Eq> Eq for Change<T>
Source§impl<T: Schema + 'static> Schema for Change<T>
impl<T: Schema + 'static> Schema for Change<T>
Source§fn schema(registry: &mut SchemaRegistry) -> SchemaObject
fn schema(registry: &mut SchemaRegistry) -> SchemaObject
The schema definition of this type. Use
SchemaRegistry::subschema for nested types.Source§fn schema_name() -> Option<&'static str>
fn schema_name() -> Option<&'static str>
Stable component name. Named types are emitted once under
components.schemas and referenced with $ref.impl<T: PartialEq> StructuralPartialEq for Change<T>
Auto Trait Implementations§
impl<T> Freeze for Change<T>where
T: Freeze,
impl<T> RefUnwindSafe for Change<T>where
T: RefUnwindSafe,
impl<T> Send for Change<T>where
T: Send,
impl<T> Sync for Change<T>where
T: Sync,
impl<T> Unpin for Change<T>where
T: Unpin,
impl<T> UnsafeUnpin for Change<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Change<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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.