yaml_rust2/
lib.rs

1// Copyright 2015, Yuheng Chen.
2// Copyright 2023, Ethiraric.
3// See the LICENSE file at the top-level directory of this distribution.
4
5//! YAML 1.2 implementation in pure Rust.
6//!
7//! # Usage
8//!
9//! This crate is [on github](https://github.com/Ethiraric/yaml-rust2) and can be used by adding
10//! `yaml-rust2` to the dependencies in your project's `Cargo.toml`.
11//!
12//! ```toml
13//! [dependencies]
14//! yaml-rust2 = "0.10.1"
15//! ```
16//!
17//! # Examples
18//! Parse a string into `Vec<Yaml>` and then serialize it as a YAML string.
19//!
20//! ```
21//! use yaml_rust2::{YamlLoader, YamlEmitter};
22//!
23//! let docs = YamlLoader::load_from_str("[1, 2, 3]").unwrap();
24//! let doc = &docs[0]; // select the first YAML document
25//! assert_eq!(doc[0].as_i64().unwrap(), 1); // access elements by index
26//!
27//! let mut out_str = String::new();
28//! let mut emitter = YamlEmitter::new(&mut out_str);
29//! emitter.dump(doc).unwrap(); // dump the YAML object to a String
30//!
31//! ```
32//!
33//! # Features
34//! **Note:** With all features disabled, this crate's MSRV is `1.65.0`.
35//!
36//! #### `encoding` (_enabled by default_)
37//! Enables encoding-aware decoding of Yaml documents.
38//!
39//! The MSRV for this feature is `1.70.0`.
40//!
41//! #### `debug_prints`
42//! Enables the `debug` module and usage of debug prints in the scanner and the parser. Do not
43//! enable if you are consuming the crate rather than working on it as this can significantly
44//! decrease performance.
45//!
46//! The MSRV for this feature is `1.70.0`.
47
48#![warn(missing_docs, clippy::pedantic)]
49
50extern crate hashlink;
51
52pub(crate) mod char_traits;
53#[macro_use]
54pub(crate) mod debug;
55pub mod emitter;
56pub mod parser;
57pub mod scanner;
58pub mod yaml;
59
60// reexport key APIs
61pub use crate::emitter::{EmitError, YamlEmitter};
62pub use crate::parser::Event;
63pub use crate::scanner::ScanError;
64pub use crate::yaml::{Yaml, YamlLoader};