Skip to main content

musli_core/en/
mod.rs

1//! Traits for generically dealing with an encoding framework.
2//!
3//! The central traits are [Encode] and [Encoder].
4//!
5//! A type implementing [Encode] can use an [Encoder] to encode itself. This
6//! also comes with a derive allowing you to derive high performance encoding
7//! associated with native Rust types.
8//!
9//! The derive in this module generates code which refers to `musli_core`, so a
10//! crate which depends on `musli_core` alone can use it without a
11//! `#[musli(crate = ..)]` attribute. If the dependency is renamed in
12//! `Cargo.toml`, point the derive at the new name with
13//! `#[musli(crate = <name>)]`.
14//!
15//! # Examples
16//!
17//! ```
18//! use musli_core::Encode;
19//!
20//! #[derive(Encode)]
21//! pub struct Person<'a> {
22//!     name: &'a str,
23//!     age: u32,
24//! }
25//! ```
26
27/// Derive which automatically implements the [`Encode` trait].
28///
29/// See the [`derives` module] for detailed documentation.
30///
31/// [`derives` module]: <https://docs.rs/musli/latest/musli/_help/derives/index.html>
32/// [`Encode` trait]: <https://docs.rs/musli/latest/musli/trait.Encode.html>
33///
34/// # Examples
35///
36/// ```
37/// use musli::Encode;
38///
39/// #[derive(Encode)]
40/// struct MyType {
41///     data: [u8; 128],
42/// }
43/// ```
44///
45/// Through `musli_core` it works the same way, with no `crate` attribute:
46///
47/// ```
48/// use musli_core::Encode;
49///
50/// #[derive(Encode)]
51/// struct MyType {
52///     data: [u8; 128],
53/// }
54/// ```
55///
56/// A crate which renames `musli_core`, such as with `musli_core01 = { package =
57/// "musli-core", .. }` in `Cargo.toml`, has to name it with `#[musli(crate =
58/// musli_core01)]`.
59#[doc(inline)]
60pub use musli_macros::MusliCoreEncode as Encode;
61
62#[doc(inline)]
63pub use self::__traits::*;
64
65mod encode;
66mod encode_bytes;
67mod encode_packed;
68mod encode_trace;
69mod encoder;
70mod entries_encoder;
71mod entry_encoder;
72mod map_encoder;
73mod sequence_encoder;
74mod variant_encoder;
75
76#[doc(hidden)]
77pub mod __traits {
78    pub use super::encode::Encode;
79    pub use super::encode_bytes::EncodeBytes;
80    pub use super::encode_packed::EncodePacked;
81    pub use super::encode_trace::EncodeTrace;
82    pub use super::encoder::{Encoder, TryFastEncode};
83    pub use super::entries_encoder::EntriesEncoder;
84    pub use super::entry_encoder::EntryEncoder;
85    pub use super::map_encoder::MapEncoder;
86    pub use super::sequence_encoder::SequenceEncoder;
87    pub use super::variant_encoder::VariantEncoder;
88}
89
90#[doc(hidden)]
91pub mod utils;