Expand description
Generic data structure deserialization framework.
The two most important traits in this module are Deserialize and
Deserializer.
- A type that implements
Deserializeis a data structure that can be deserialized from any data format supported by Serde, and conversely - A type that implements
Deserializeris a data format that can deserialize any data structure supported by Serde.
§The Deserialize trait
Serde provides Deserialize implementations for many Rust primitive and
standard library types. The complete list is below. All of these can be
deserialized using Serde out of the box.
Additionally, Serde provides a procedural macro called serde_derive to
automatically generate Deserialize implementations for structs and enums
in your program. See the derive section of the manual for how to use this.
In rare cases it may be necessary to implement Deserialize manually for
some type in your program. See the Implementing Deserialize section of
the manual for more about this.
Third-party crates may provide Deserialize implementations for types
that they expose. For example the linked-hash-map crate provides a
LinkedHashMap<K, V> type that is deserializable by Serde because the
crate provides an implementation of Deserialize for it.
§The Deserializer trait
Deserializer implementations are provided by third-party crates, for
example serde_json, serde_yaml and postcard.
A partial list of well-maintained formats is given on the Serde website.
§Implementations of Deserialize provided by Serde
This is a slightly different set of types than what is supported for
serialization. Some types can be serialized by Serde but not deserialized.
One example is OsStr.
- Primitive types:
- bool
- i8, i16, i32, i64, i128, isize
- u8, u16, u32, u64, u128, usize
- f32, f64
- char
- Compound types:
- [T; 0] through [T; 32]
- tuples up to size 16
- Common standard library types:
- String
- Option<T>
- Result<T, E>
- PhantomData<T>
- Wrapper types:
- Box<T>
- Box<[T]>
- Box<str>
- Cow<’a, T>
- Cell<T>
- RefCell<T>
- Mutex<T>
- RwLock<T>
- Rc<T> (if features = [“rc”] is enabled)
- Arc<T> (if features = [“rc”] is enabled)
- Collection types:
- BTreeMap<K, V>
- BTreeSet<T>
- BinaryHeap<T>
- HashMap<K, V, H>
- HashSet<T, H>
- LinkedList<T>
- VecDeque<T>
- Vec<T>
- Zero-copy types:
- &str
- &[u8]
- FFI types:
- CString
- Box<CStr>
- OsString
- Miscellaneous standard library types:
- Duration
- SystemTime
- Path
- PathBuf
- Range<T>
- RangeInclusive<T>
- Bound<T>
- num::NonZero*
!(unstable)
- Net types:
- IpAddr
- Ipv4Addr
- Ipv6Addr
- SocketAddr
- SocketAddrV4
- SocketAddrV6
Re-exports§
pub use std::error::Error as StdError;
Modules§
- value
- Building blocks for deserializing basic values using the
IntoDeserializertrait.
Structs§
- Ignored
Any - An efficient way of discarding data from a deserializer.
Enums§
- Unexpected
Unexpectedrepresents an unexpected invocation of any one of theVisitortrait methods.
Traits§
- Deserialize
- A data structure that can be deserialized from any data format supported by Serde.
- Deserialize
Owned - A data structure that can be deserialized without borrowing any data from the deserializer.
- Deserialize
Seed DeserializeSeedis the stateful form of theDeserializetrait. If you ever find yourself looking for a way to pass data into aDeserializeimpl, this trait is the way to do it.- Deserializer
- A data format that can deserialize any data structure supported by Serde.
- Enum
Access - Provides a
Visitoraccess to the data of an enum in the input. - Error
- The
Errortrait allowsDeserializeimplementations to create descriptive error messages belonging to theDeserializeragainst which they are currently running. - Expected
Expectedrepresents an explanation of what data aVisitorwas expecting to receive.- Into
Deserializer - Converts an existing value into a
Deserializerfrom which other values can be deserialized. - MapAccess
- Provides a
Visitoraccess to each entry of a map in the input. - SeqAccess
- Provides a
Visitoraccess to each element of a sequence in the input. - Variant
Access VariantAccessis a visitor that is created by theDeserializerand passed to theDeserializeto deserialize the content of a particular enum variant.- Visitor
- This trait represents a visitor that walks through a deserializer.