noyalib/with/mod.rs
1//! Helper modules for customizing serialization and deserialization.
2//!
3//! This module provides utilities for controlling how certain types are
4//! serialized and deserialized, particularly enums.
5//!
6//! # Singleton Map
7//!
8//! The `singleton_map` family of modules provides helpers for serializing
9//! enums as single-entry maps, which is a common YAML pattern.
10//!
11//! ## Example
12//!
13//! ```rust
14//! use noyalib::with::singleton_map;
15//!
16//! #[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq)]
17//! enum Action {
18//! Start { delay: u32 },
19//! Stop,
20//! }
21//!
22//! #[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq)]
23//! struct Task {
24//! name: String,
25//! #[serde(with = "singleton_map")]
26//! action: Action,
27//! }
28//!
29//! let task = Task {
30//! name: "my-task".to_string(),
31//! action: Action::Start { delay: 5 },
32//! };
33//!
34//! let yaml = noyalib::to_string(&task).unwrap();
35//! // Output:
36//! // name: my-task
37//! // action:
38//! // Start:
39//! // delay: 5
40//! ```
41
42// SPDX-License-Identifier: MIT OR Apache-2.0
43// Copyright (c) 2026 Noyalib. All rights reserved.
44
45pub mod singleton_map;
46pub mod singleton_map_optional;
47pub mod singleton_map_recursive;
48pub mod singleton_map_with;
49
50/// Alias for `singleton_map_recursive`.
51///
52/// This provides compatibility with code that uses the `nested_singleton_map`
53/// name.
54pub use singleton_map_recursive as nested_singleton_map;