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)
A call to serde::Serializer::serialize_str
.
ByteArray(Vec<u8>)
A call to serde::Serializer::serialize_bytes
.
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);
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),
// ...
}
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
.
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
.
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
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
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, E> Save<'a, E>
impl<'a, E> Save<'a, E>
Sourcepub fn strukt<V>(
name: &'a str,
fields: impl IntoIterator<Item = (&'a str, V)>,
) -> Self
pub fn strukt<V>( name: &'a str, fields: impl IntoIterator<Item = (&'a str, V)>, ) -> Self
Convenience method for creating a Save::Struct
with no skipped fields.
Sourcepub fn string(it: impl Into<String>) -> Self
pub fn string(it: impl Into<String>) -> Self
Convenience method for creating a Save::String
Trait Implementations§
Source§impl<'a, 'de> Deserialize<'de> for Save<'a>
This is a best-effort deserialization, provided for completeness.
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>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'a, E, T0, T1, T2> From<(T0, T1, T2)> for Save<'a, E>
You can construct a Save::Tuple
using From
for tuples of arities
between 1 and 24, except 2.
impl<'a, E, T0, T1, T2> From<(T0, T1, T2)> for 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
fn from((t0, t1, t2): (T0, T1, T2)) -> Self
Source§impl<'a, E, K, V> FromIterator<(K, V)> for Save<'a, E>
impl<'a, E, K, V> FromIterator<(K, V)> for Save<'a, E>
Source§impl<'a, E, T> FromIterator<T> for Save<'a, E>
impl<'a, E, T> FromIterator<T> for Save<'a, E>
Source§fn from_iter<II: IntoIterator<Item = T>>(iter: II) -> Self
fn from_iter<II: IntoIterator<Item = T>>(iter: II) -> Self
Source§impl<'a, E: PartialOrd> PartialOrd for Save<'a, E>
impl<'a, E: PartialOrd> PartialOrd for Save<'a, E>
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.
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.