Expand description
deser: an experimental serialization and deserialization library for Rust
Deser is an experimental serialization system for Rust. It wants to explore the possibilities of serialization and deserialization of structural formats such as JSON or msgpack. It intentionally does not desire to support non self describing formats such as bincode.
With the derive feature it supports deriving structures that can be
serialized and deserialized automatically:
use deser::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
#[deser(rename_all = "camelCase")]
pub struct Account {
id: usize,
account_holder: String,
is_deactivated: bool,
}To serialize or deserialize this a data format implementation is needed. At the moment the following formats are supported:
deser-json: implements JSON serialization and deserialization.deser-jsonc: implements deserialization of JSONC (JSON with comments, as used by configuration files) and serialization as JSON.deser-json5: implements deserialization of JSON5 and serialization as JSON.deser-hj: implements deserialization of Hjson and serialization as JSON.deser-cbor: implements CBOR serialization and deserialization.deser-msgpack: implements MessagePack serialization and deserialization.deser-toml: implements TOML serialization and deserialization.deser-yaml: implements YAML serialization and deserialization.deser-urlencoded: implements query string and form data (application/x-www-form-urlencoded) serialization and deserialization.deser-xml: implements XML serialization and deserialization.deser-plist: implements property list (XML, binary and OpenStep) serialization and deserialization.deser-csv: implements CSV, TSV and other delimited text serialization and deserialization.deser-env: implements reading configuration from environment variables (and writing values into them).
The data formats have a deserializer (which deserializes values from a
slice) and a serializer (which serializes values into a buffer). Values
can also be read from and written to streams (such as files or sockets),
see io. The stream serializers and deserializers of the
formats do not do IO themselves (see stream), so they also work with
other kinds of IO and without the standard library.
The data model can be extended with types that are not native to it. For
more information see ext.
How individual values are serialized and deserialized can be customized
with adapters, which compose with containers. For more information see
adapters. Types which only implement serde’s traits can be used with
the adapters of deser-serde. Bytes are
base64 strings in formats without native bytes, more encodings (such as
hexadecimal and base32) are provided by
deser-encoding.
Further functionality is provided by these crates:
deser-value: a dynamic value type which can hold any value of the data model, to inspect or transform data or to convert between formats.deser-path: a layer that tracks the path of the current value (likeservers[1].timeout) and attaches it to errors.deser-validate: validates values while they are deserialized.deser-location: resolves the source locations (line and column) of values while they are deserialized.deser-debug: formats serializable values like theirDebugimplementation would.deser-tokio: reads and writes values with tokio’s asynchronous streams.deser-serde: adapters to use serde types.deser-encoding: hexadecimal and base32 encodings of bytes.
§Features
deriveturns on basic derive support forSerializeandDeserialize. For more information seederive.jiff,chrono,time,uuid,rust_decimal,bigdecimalandnum-bigintimplementSerializeandDeserializefor the types of these crates. They are serialized as well-known types which data formats can support natively.indexmap,hashbrown,smallvec,arrayvec,bytesandbstrimplementSerializeandDeserializefor the collections and byte buffers of these crates. They behave like their counterparts in the standard library, including the adapters (for instanceIndexMap<_, DisplayFromStr>). Withoutstdthe adapters ofIndexMapandIndexSetare not available.io(enabled by default) addsioto read values from and write values to streams of the standard library (std::io). It requiresstd. Reading and writing streams without IO (seestream) does not need it.std(enabled by default) uses the standard library, see below.
§no_std
Without the std feature deser only needs alloc (a global allocator)
and works on targets without an operating system. Disable the default
features of deser and of the formats (deser-json, deser-jsonc,
deser-json5, deser-hj, deser-cbor, deser-msgpack,
deser-plist and deser-csv support this):
[dependencies]
deser-cbor = { version = "0.8", default-features = false }
[dependencies.deser]
version = "0.8"
default-features = false
features = ["derive"]Everything that is not in core and alloc is not available: io,
the implementations for HashMap and HashSet (use the hashbrown
feature instead), Path, OsStr, SystemTime, Mutex, RwLock and
OnceLock.
Re-exports§
pub use crate::de::Deserialize;pub use crate::ser::Serialize;pub use crate::stream::Streamed;
Modules§
- adapters
- Adapters to customize how values are serialized and deserialized.
- de
- Generic data structure deserialization framework.
- derive
derive - Support for automatic serializer and deserializer deriving.
- ext
- Extensions to the data model.
- hints
- Well-known formatting hints.
- io
io - Reading and writing values from and to streams.
- ser
- Generic data structure serialization framework.
- stream
- Reading and writing streams of values without doing IO.
Macros§
- make_
slot_ wrapper - Creates a newtype wrapper around
Option<T>.
Structs§
- Bytes
- Bytes in the data model.
- Bytes
Format - How bytes are represented in formats without native bytes.
- Container
Shape - Facts about a map or sequence.
- Error
- An error for deser.
- Event
Data - Data attached to an event, detached from the event.
- Implicit
- A value whose type the format inferred from its text.
- Position
- A position in the input.
- Source
- The source the input ranges refer to.
- State
- Gives access to the state of an ongoing serialization or deserialization.
- Text
- Text of an
Atom, borrowed or owned.
Enums§
- Atom
- An atom is a primitive value for serialization and deserialization.
- Error
Kind - Describes the kind of error.
- Event
- An event represents an atomic serialization and deserialization event.
- Implicit
Value - The value of an
Implicitatom. - Order
- How significant the order of the elements of a container is.
Traits§
- Error
Attachment - Additional information attached to an
Error. - Error
Context - Adds context to errors, see
State::add_error_context.
Derive Macros§
- Deserialize
derive - Derives
Deserializefor a struct or enum. - Serialize
derive - Derives
Serializefor a struct or enum.