deser/
lib.rs

1//! <div align="center">
2//!  <img src="https://raw.githubusercontent.com/mitsuhiko/deser/main/artwork/logo.svg" width="250" height="250">
3//!  <p><strong>deser: an experimental serialization and deserialization library for Rust</strong></p>
4//! </div>
5//!
6//! Deser is an experimental serialization system for Rust.  It wants to explore
7//! the possibilities of serialization and deserialization of structural formats
8//! such as JSON or msgpack.  It intentionally does not desire to support non
9//! self describing formats such as bincode.
10//!
11//! There is not much in terms of actual serialization and deserialization yet
12//! as this library at this point is an exploration in API design for the
13//! abstraction layer itself.
14//!
15//! **This is not a production ready yet.**
16//!
17#![cfg_attr(
18    feature = "derive",
19    doc = r#"
20```rust
21use deser::{Serialize, Deserialize};
22
23#[derive(Debug, Serialize, Deserialize)]
24#[deser(rename_all = "camelCase")]
25pub struct Account {
26    id: usize,
27    account_holder: String,
28    is_deactivated: bool,
29}
30```
31"#
32)]
33//!
34//! For more information have a look at the GitHub repository:
35//! [mitsuhiko/deser](https://github.com/mitsuhiko/deser).
36//!
37//! ## Features
38//!
39//! * `derive` turns on basic derive support for [`Serialize`] and [`Deserialize`].  For more
40//!   information see [`derive`](crate::derive).
41
42#[macro_use]
43mod macros;
44mod event;
45
46pub mod de;
47mod error;
48pub mod ser;
49
50mod descriptors;
51mod extensions;
52
53pub use self::descriptors::Descriptor;
54pub use self::error::{Error, ErrorKind};
55pub use self::event::{Atom, Event};
56
57// common re-exports
58
59#[doc(no_inline)]
60pub use self::{de::Deserialize, ser::Serialize};
61
62#[cfg(feature = "derive")]
63#[doc(no_inline)]
64pub use self::derive::{Deserialize, Serialize};
65
66#[cfg(feature = "derive")]
67pub mod derive;
68
69// These are re-exported fro the derive macro.  There is no good
70// reason for this right now as deser does not yet have no-std
71// support but this will make it easier later to add support.
72#[cfg(feature = "derive")]
73#[doc(hidden)]
74pub mod __derive {
75    pub use std::borrow::Cow;
76    pub use std::boxed::Box;
77    pub use std::default::Default;
78    pub use std::option::Option::{self, None, Some};
79    pub use std::result::Result::{Err, Ok};
80    pub type Result<T> = std::result::Result<T, super::Error>;
81    pub type StrCow<'a> = Cow<'a, str>;
82
83    pub fn new_missing_field_error(name: &str) -> super::Error {
84        super::Error::new(
85            super::ErrorKind::MissingField,
86            format!("Missing field '{}'", name),
87        )
88    }
89
90    mod _hack {
91        pub type Str = str;
92    }
93    pub use self::_hack::Str as str;
94}