deku_string/
lib.rs

1#![no_std]
2#![deny(missing_docs)]
3#![deny(missing_debug_implementations)]
4#![forbid(clippy::allow_attributes_without_reason)]
5
6//! Utility crate for [`Deku`] that provides convenient support for serializing and
7//! deserializing String and Vec in a variety of binary formats.
8//!
9//! Some notable features:
10//!
11//! * [`StringDeku`] supports UTF-8, UTF-16 and UTF-32 encodings.
12//! * Multiple layouts such as .Net, Pascal and zero-ended.
13//! * Little and Big Endian support.
14//! * Dynamic read and write without additional temporary structs and operations.
15//! * No need to specify custom reader and writer functions.
16//! * Compatible with Deku's derive macros and custom readers/writers.
17//! * Supports `serde` and `defmt`.
18//!
19//! Read specific struct for example usage.
20//!
21//! [`Deku`]: https://docs.rs/deku
22
23#[cfg(target_pointer_width = "16")]
24compile_error!("Feel free to make a PR if you need this");
25
26extern crate alloc;
27
28mod common;
29mod seven_bit;
30mod string;
31mod vec;
32
33pub(crate) use common::InternalValue;
34pub(crate) use common::deku_impl::{read_size_prefix, write_size_prefix};
35pub(crate) use common::serde_impl::serde_shim_implementation;
36pub(crate) use common::std_impl::std_shim_implementation;
37
38pub use seven_bit::{SevenBitU8, SevenBitU16, SevenBitU32, SevenBitU64, SevenBitU128};
39pub use string::{Encoding, StringDeku, StringLayout};
40pub use vec::{VecDeku, VecLayout};
41
42/// Size encoding for length-prefixed [`StringDeku`] and [`VecDeku`]
43#[derive(Debug, Clone, Copy)]
44#[non_exhaustive]
45pub enum Size {
46    /// 1 byte to encode length.
47    U8,
48
49    /// 2 bytes to encode length.
50    U16,
51
52    /// 4 bytes to encode length.
53    U32,
54
55    /// 7bit encoded u32 to encode length (.Net style).
56    ///
57    /// See [`crate::SevenBitU32`] for details.
58    U32_7Bit,
59}