weakauras_codec_lib_serialize/
lib.rs

1// Copyright 2020-2025 Velithris
2// SPDX-License-Identifier: MIT
3
4//! This library provides routines for deserializing and serializing [`LuaValues`](LuaValue)
5//! in a way compatible with a Lua library called LibSerialize.
6//!
7//! # Deserialization example
8//!
9//! This is how you can use the library to deserialize strings produced by LibSerialize.
10//!
11//! ```
12//! use weakauras_codec_lib_serialize::{DeserializationError, Deserializer};
13//!
14//! fn main() -> Result<(), DeserializationError> {
15//!     assert_eq!(
16//!         Deserializer::from_slice(b"\x01\xd2Hello, world!")
17//!             .deserialize_first()?
18//!             .unwrap(),
19//!         "Hello, world!".into()
20//!     );
21//!     Ok(())
22//! }
23//! ```
24//!
25//! # Serialization example
26//!
27//! This is how you can use the library to serialize values in a way compatible with LibSerialize.
28//!
29//! ```
30//! use weakauras_codec_lib_serialize::{SerializationError, Serializer};
31//!
32//! fn main() -> Result<(), SerializationError> {
33//!     assert_eq!(
34//!         Serializer::serialize_one(&"Hello, world!".into(), None)?,
35//!         b"\x01\xd2Hello, world!"
36//!     );
37//!     Ok(())
38//! }
39//! ```
40//!
41//! # Crate features
42//!
43//! * **lua-value-arbitrary** - Implement `arbitrary::Arbitrary` for [`LuaValue`]. **Disabled** by default.
44//! * **lua-value-fnv** - Use `fnv` instead of `BTreeMap` as the implementation of [`LuaValue::Map`]. **Disabled** by default.
45//! * **lua-value-indexmap** - Use `indexmap` instead of `BTreeMap` as the implementation of [`LuaValue::Map`]. **Disabled** by default.
46//! * **serde** - Allow serializing and deserializing [`LuaValue`] using `serde`. **Disabled** by default.
47
48#![deny(missing_docs)]
49
50/// Deserialization.
51pub mod deserialization;
52/// Error types.
53pub mod error;
54pub(crate) mod macros;
55/// Serialization.
56pub mod serialization;
57pub(crate) mod type_tag;
58
59pub use deserialization::Deserializer;
60pub use error::*;
61pub use serialization::Serializer;
62pub(crate) use type_tag::{EmbeddedTypeTag, TypeTag};
63pub use weakauras_codec_lua_value::LuaValue;
64
65pub(crate) const FORMAT_VERSION: u8 = 1;