Enum Save

Source
pub enum Save<'a, E = Infallible> {
Show 30 variants Bool(bool), I8(i8), I16(i16), I32(i32), I64(i64), I128(i128), U8(u8), U16(u16), U32(u32), U64(u64), U128(u128), F32(f32), F64(f64), Char(char), String(String), ByteArray(Vec<u8>), Option(Option<Box<Self>>), Unit, UnitStruct(&'a str), UnitVariant(Variant<'a>), NewTypeStruct { name: &'a str, value: Box<Self>, }, NewTypeVariant { variant: Variant<'a>, value: Box<Self>, }, Seq(Vec<Self>), Map(Vec<(Self, Self)>), Tuple(Vec<Self>), TupleStruct { name: &'a str, values: Vec<Self>, }, TupleVariant { variant: Variant<'a>, values: Vec<Self>, }, Struct { name: &'a str, fields: Vec<(&'a str, Option<Self>)>, }, StructVariant { variant: Variant<'a>, fields: Vec<(&'a str, Option<Self>)>, }, Error(E),
}
Expand description

A complete serde serialization tree.

Accepts a lifetime to allow users to write dynamic tests.

See crate documentation for more.

Variants§

§

Bool(bool)

Primitive type, from a call to serde::Serializer::serialize_bool.

§

I8(i8)

Primitive type, from a call to serde::Serializer::serialize_i8.

§

I16(i16)

Primitive type, from a call to serde::Serializer::serialize_i16.

§

I32(i32)

Primitive type, from a call to serde::Serializer::serialize_i32.

§

I64(i64)

Primitive type, from a call to serde::Serializer::serialize_i64.

§

I128(i128)

Primitive type, from a call to serde::Serializer::serialize_i128.

§

U8(u8)

Primitive type, from a call to serde::Serializer::serialize_u8.

§

U16(u16)

Primitive type, from a call to serde::Serializer::serialize_u16.

§

U32(u32)

Primitive type, from a call to serde::Serializer::serialize_u32.

§

U64(u64)

Primitive type, from a call to serde::Serializer::serialize_u64.

§

U128(u128)

Primitive type, from a call to serde::Serializer::serialize_u128.

§

F32(f32)

Primitive type, from a call to serde::Serializer::serialize_f32.

§

F64(f64)

Primitive type, from a call to serde::Serializer::serialize_f64.

§

Char(char)

Primitive type, from a call to serde::Serializer::serialize_char.

§

String(String)

§

ByteArray(Vec<u8>)

§

Option(Option<Box<Self>>)

§

Unit

The empty tuple, from a call to serde::Serializer::serialize_unit.

§

UnitStruct(&'a str)

A unit struct, from a call to serde::Serializer::serialize_unit_struct.

struct MyUnitStruct;
§

UnitVariant(Variant<'a>)

A unit variant of an enum, from a call to serde::Serializer::serialize_unit_variant.

enum MyEnum {
    MyUnitVariant,
    // ...
}
§

NewTypeStruct

A tuple struct with a single unnamed field, from a call to serde::Serializer::serialize_newtype_struct.

struct MyStruct(A);

Fields

§name: &'a str
§value: Box<Self>
§

NewTypeVariant

A tuple variant of an enum with a single unnamed field, from a call to serde::Serializer::serialize_newtype_variant.

enum MyEnum {
    MyNewTypeVariant(A),
    // ...
}

Fields

§variant: Variant<'a>
§value: Box<Self>
§

Seq(Vec<Self>)

A dynamic sequence of values, from a call to serde::Serializer::serialize_seq.

If protocol errors are enabled, checks that the number of items matches the length (if any) passed to the call to serialize_seq.

§

Map(Vec<(Self, Self)>)

A dynamic mapping between values, from a call to serde::Serializer::serialize_map.

If protocol errors are enabled, checks that the number of items matches the length (if any) passed to the call to serialize_map.

Note:

  • Orphaned keys or values are always an error.
  • Duplicate map keys are always allowed.
§

Tuple(Vec<Self>)

A fixed sequence of values, from a call to serde::Serializer::serialize_tuple.

(A, B, C);

If protocol errors are enabled, checks that the number of items matches the length passed to the call to serialize_tuple.

§

TupleStruct

A fixed sequence of unnamed fields in a struct, from a call to serde::Serializer::serialize_tuple_struct.

struct MyTupleStruct(A, B, C);

If protocol errors are enabled, checks that the number of items matches the length passed to the call to serialize_tuple_struct.

Fields

§name: &'a str
§values: Vec<Self>
§

TupleVariant

A fixed sequence of unnamed fields in an enum variant, from a call to serde::Serializer::serialize_tuple_variant.

enum MyEnum {
    MyTupleVariant(A, B, C),
    // ...
}

If protocol errors are enabled, checks that the number of items matches the length passed to the call to serialize_tuple_variant.

Fields

§variant: Variant<'a>
§values: Vec<Self>
§

Struct

A fixed mapping from field names to values in a struct, from a call to serde::Serializer::serialize_struct.

struct MyStruct {
    num_yaks: usize,
    shepherd_name: String,
}

If protocol errors are enabled, checks that:

  • the number of items matches the length passed to the call to serialize_struct.
  • all fields are unique

Fields

§name: &'a str
§fields: Vec<(&'a str, Option<Self>)>

RHS is None for skiped fields.

For in-tree errors, the field name is "!error".

§

StructVariant

A fixed mapping from named fields to values in an enum variant, from a call to serde::Serializer::serialize_struct_variant.

enum MyEnum {
    MyStructVariant {
        num_yaks: usize,
        shepherd_name: String,
    },
    // ...
}

If protocol errors are enabled, checks that:

  • the number of items matches the length passed to the call to serialize_struct_variant.
  • all fields are unique

Fields

§variant: Variant<'a>
§fields: Vec<(&'a str, Option<Self>)>

RHS is None for skiped fields.

For in-tree errors, the field name is "!error".

§

Error(E)

An in-tree persisted error.

Note that this is uninhabited by default, and you can prove it to be unreachable in your code:


fn stringify(save: Save) -> String {
    match save {
        // the compiler knows this branch won't be hit, so coerced the
        // empty match to String
        Save::Error(e) => match e {},
        // ...
    }
}

However, if errors are persisted, you can inspect them

let save: Save<Error>;
match save {
    Save::Error(e) => {
        println!("{}", e);
        if e.is_protocol() { /* .. */ }
    }
    // ...
}

Implementations§

Source§

impl<'a> Save<'a, Error>

Source

pub fn error(msg: impl Display) -> Self

Convenience method for creating a custom error.

Source§

impl<'a, E> Save<'a, E>

Source

pub fn strukt<V>( name: &'a str, fields: impl IntoIterator<Item = (&'a str, V)>, ) -> Self
where V: Into<Save<'a, E>>,

Convenience method for creating a Save::Struct with no skipped fields.

Source

pub fn string(it: impl Into<String>) -> Self

Convenience method for creating a Save::String

Source

pub fn bytes(it: impl Into<Vec<u8>>) -> Self

Convenience method for creating a Save::ByteArray

Trait Implementations§

Source§

impl<'a, E: Clone> Clone for Save<'a, E>

Source§

fn clone(&self) -> Save<'a, E>

Returns a copy 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<'a, E: Debug> Debug for Save<'a, E>

Source§

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

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

impl<'a, 'de> Deserialize<'de> for Save<'a>

This is a best-effort deserialization, provided for completeness.

Source§

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

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

impl<'a, E> From<()> for Save<'a, E>

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl<'a, E, T0, T1, T2> From<(T0, T1, T2)> for Save<'a, E>
where T0: Into<Save<'a, E>>, T1: Into<Save<'a, E>>, T2: Into<Save<'a, E>>,

You can construct a Save::Tuple using From for tuples of arities between 1 and 24, except 2.

The other implementations are hidden from rustdoc for brevity.

Source§

fn from((t0, t1, t2): (T0, T1, T2)) -> Self

Converts to this type from the input type.
Source§

impl<'a, E, T> From<Option<T>> for Save<'a, E>
where T: Into<Save<'a, E>>,

Source§

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

Converts to this type from the input type.
Source§

impl<'a, E> From<String> for Save<'a, E>

Source§

fn from(it: String) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<Variant<'a>> for Save<'a, E>

Source§

fn from(it: Variant<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<Vec<u8>> for Save<'a, E>

Source§

fn from(it: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<bool> for Save<'a, E>

Source§

fn from(it: bool) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<char> for Save<'a, E>

Source§

fn from(it: char) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<f32> for Save<'a, E>

Source§

fn from(it: f32) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<f64> for Save<'a, E>

Source§

fn from(it: f64) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<i128> for Save<'a, E>

Source§

fn from(it: i128) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<i16> for Save<'a, E>

Source§

fn from(it: i16) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<i32> for Save<'a, E>

Source§

fn from(it: i32) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<i64> for Save<'a, E>

Source§

fn from(it: i64) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<i8> for Save<'a, E>

Source§

fn from(it: i8) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<u128> for Save<'a, E>

Source§

fn from(it: u128) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<u16> for Save<'a, E>

Source§

fn from(it: u16) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<u32> for Save<'a, E>

Source§

fn from(it: u32) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<u64> for Save<'a, E>

Source§

fn from(it: u64) -> Self

Converts to this type from the input type.
Source§

impl<'a, E> From<u8> for Save<'a, E>

Source§

fn from(it: u8) -> Self

Converts to this type from the input type.
Source§

impl<'a, E, K, V> FromIterator<(K, V)> for Save<'a, E>
where K: Into<Save<'a, E>>, V: Into<Save<'a, E>>,

Source§

fn from_iter<II: IntoIterator<Item = (K, V)>>(iter: II) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, E, T> FromIterator<T> for Save<'a, E>
where T: Into<Save<'a, E>>,

Source§

fn from_iter<II: IntoIterator<Item = T>>(iter: II) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, E: PartialEq> PartialEq for Save<'a, E>

Source§

fn eq(&self, other: &Save<'a, E>) -> 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<'a, E: PartialOrd> PartialOrd for Save<'a, E>

Source§

fn partial_cmp(&self, other: &Save<'a, E>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<E> Serialize for Save<'static, E>
where E: Display,

If protocol errors are disabled, this will perfectly preserve the underlying structure of the originally saved item.

Source§

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

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

impl<'a, E> StructuralPartialEq for Save<'a, E>

Auto Trait Implementations§

§

impl<'a, E> Freeze for Save<'a, E>
where E: Freeze,

§

impl<'a, E> RefUnwindSafe for Save<'a, E>
where E: RefUnwindSafe,

§

impl<'a, E> Send for Save<'a, E>
where E: Send,

§

impl<'a, E> Sync for Save<'a, E>
where E: Sync,

§

impl<'a, E> Unpin for Save<'a, E>
where E: Unpin,

§

impl<'a, E> UnwindSafe for Save<'a, E>
where E: 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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 = 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,