facet_yaml_legacy/lib.rs
1//! Legacy YAML serialization and deserialization for Facet types.
2//!
3//! **Note**: This crate is deprecated. Please use `facet-yaml` instead, which provides
4//! the modern format-based implementation.
5//!
6//! This crate provides YAML parsing using a streaming event-based parser (saphyr-parser)
7//! and integrates with the facet reflection system for type-safe deserialization.
8//!
9//! # Example
10//!
11//! ```
12//! use facet::Facet;
13//! use facet_yaml_legacy::from_str;
14//!
15//! #[derive(Facet, Debug, PartialEq)]
16//! struct Config {
17//! name: String,
18//! port: u16,
19//! }
20//!
21//! let yaml = "name: myapp\nport: 8080";
22//! let config: Config = from_str(yaml).unwrap();
23//! assert_eq!(config.name, "myapp");
24//! assert_eq!(config.port, 8080);
25//! ```
26
27#![cfg_attr(not(feature = "std"), no_std)]
28#![warn(missing_docs)]
29#![warn(clippy::std_instead_of_core)]
30#![warn(clippy::std_instead_of_alloc)]
31
32extern crate alloc;
33
34mod deserialize;
35mod error;
36#[cfg(feature = "std")]
37mod serialize;
38
39pub use deserialize::{from_str, from_str_borrowed};
40pub use error::{YamlError, YamlErrorKind};
41#[cfg(feature = "std")]
42pub use serialize::{to_string, to_writer};
43
44mod yaml;
45pub use yaml::Yaml;
46
47#[cfg(feature = "axum")]
48mod axum;
49#[cfg(feature = "axum")]
50pub use self::axum::YamlRejection;
51
52// Re-export span types from facet-reflect
53pub use facet_reflect::{Span, Spanned};
54
55/// Serde-compatible extension attributes for YAML serialization.
56///
57/// This module provides extension attributes that mirror serde's attribute syntax,
58/// allowing users to write `#[facet(serde::rename = "name")]` for field renaming.
59///
60/// Users import `use facet_yaml_legacy::serde;` to use these attributes.
61pub mod serde {
62 // Generate serde attribute grammar using the grammar DSL.
63 // This generates:
64 // - `Attr` enum with all serde attribute variants
65 // - `__attr!` macro that dispatches to attribute handlers and returns ExtensionAttr
66 // - `__parse_attr!` macro for parsing (internal use)
67 facet::define_attr_grammar! {
68 ns "serde";
69 crate_path ::facet_yaml_legacy::serde;
70
71 /// Serde-compatible attribute types for field and container configuration.
72 pub enum Attr {
73 /// Rename a field during serialization/deserialization.
74 ///
75 /// Usage: `#[facet(serde::rename = "new_name")]`
76 Rename(&'static str),
77 }
78 }
79}