pub trait Deserialize<'de>: Sized {
// Required method
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>;
// Provided method
#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), D::Error>
where D: Deserializer<'de> { ... }
}
Expand description
A data structure that can be deserialized from any data format supported by Serde.
Serde provides Deserialize
implementations for many Rust primitive and
standard library types. The complete list is here. 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.
§Lifetime
The 'de
lifetime of this trait is the lifetime of data that may be
borrowed by Self
when deserialized. See the page Understanding
deserializer lifetimes for a more detailed explanation of these lifetimes.
Required Methods§
sourcefn 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>,
Deserialize this value from the given Serde deserializer.
See the Implementing Deserialize
section of the
manual for more information about how to implement this method.
Provided Methods§
source#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), D::Error>where
D: Deserializer<'de>,
#[doc(hidden)] fn deserialize_in_place<D>(
deserializer: D,
place: &mut Self,
) -> Result<(), D::Error>where
D: Deserializer<'de>,
Deserializes a value into self
from the given Deserializer.
The purpose of this method is to allow the deserializer to reuse
resources and avoid copies. As such, if this method returns an error,
self
will be in an indeterminate state where some parts of the struct
have been overwritten. Although whatever state that is will be
memory-safe.
This is generally useful when repeatedly deserializing values that
are processed one at a time, where the value of self
doesn’t matter
when the next deserialization occurs.
If you manually implement this, your recursive deserializations should
use deserialize_in_place
.
This method is stable and an official public API, but hidden from the documentation because it is almost never what newbies are looking for. Showing it in rustdoc would cause it to be featured more prominently than it deserves.