2024-02-08 06:12:14 +00:00
|
|
|
// Copyright 2015, Yuheng Chen.
|
|
|
|
// Copyright 2023, Ethiraric.
|
|
|
|
// See the LICENSE file at the top-level directory of this distribution.
|
2015-05-31 09:59:43 +00:00
|
|
|
|
|
|
|
//! YAML 1.2 implementation in pure Rust.
|
|
|
|
//!
|
|
|
|
//! # Usage
|
|
|
|
//!
|
2024-04-02 16:49:52 +00:00
|
|
|
//! This crate is [on github](https://github.com/saphyr-rs/saphyr) and can be used by adding
|
|
|
|
//! `saphyr` to the dependencies in your project's `Cargo.toml`.
|
2015-05-31 09:59:43 +00:00
|
|
|
//! ```toml
|
2021-07-12 07:48:17 +00:00
|
|
|
//! [dependencies]
|
2024-04-02 16:49:52 +00:00
|
|
|
//! saphyr = "0.0.1"
|
|
|
|
//! ```
|
|
|
|
//! or by using `cargo add` to get the latest version:
|
|
|
|
//! ```sh
|
|
|
|
//! cargo add saphyr
|
2015-05-31 09:59:43 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Examples
|
2023-08-17 00:17:40 +00:00
|
|
|
//! Parse a string into `Vec<Yaml>` and then serialize it as a YAML string.
|
2015-05-31 09:59:43 +00:00
|
|
|
//!
|
|
|
|
//! ```
|
2024-06-13 20:37:56 +00:00
|
|
|
//! use saphyr::{Yaml, YamlEmitter};
|
2015-05-31 09:59:43 +00:00
|
|
|
//!
|
2024-06-13 20:37:56 +00:00
|
|
|
//! let docs = Yaml::load_from_str("[1, 2, 3]").unwrap();
|
2023-08-17 00:17:40 +00:00
|
|
|
//! let doc = &docs[0]; // select the first YAML document
|
2015-05-31 09:59:43 +00:00
|
|
|
//! assert_eq!(doc[0].as_i64().unwrap(), 1); // access elements by index
|
2015-06-29 16:31:22 +00:00
|
|
|
//!
|
2015-05-31 09:59:43 +00:00
|
|
|
//! let mut out_str = String::new();
|
|
|
|
//! let mut emitter = YamlEmitter::new(&mut out_str);
|
|
|
|
//! emitter.dump(doc).unwrap(); // dump the YAML object to a String
|
|
|
|
//! ```
|
2024-03-30 18:24:54 +00:00
|
|
|
//!
|
|
|
|
//! # Features
|
2024-03-30 18:39:53 +00:00
|
|
|
//! **Note:** With all features disabled, this crate's MSRV is `1.65.0`.
|
|
|
|
//!
|
2024-03-30 18:24:54 +00:00
|
|
|
//! #### `encoding` (_enabled by default_)
|
|
|
|
//! Enables encoding-aware decoding of Yaml documents.
|
|
|
|
//!
|
2024-03-30 18:39:53 +00:00
|
|
|
//! The MSRV for this feature is `1.70.0`.
|
2015-05-31 09:59:43 +00:00
|
|
|
|
2024-03-20 14:50:48 +00:00
|
|
|
#![warn(missing_docs, clippy::pedantic)]
|
2024-03-19 17:18:59 +00:00
|
|
|
|
2024-06-10 20:39:13 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod macros;
|
|
|
|
|
|
|
|
mod annotated;
|
2024-06-10 16:05:25 +00:00
|
|
|
mod char_traits;
|
|
|
|
mod emitter;
|
|
|
|
mod loader;
|
|
|
|
mod yaml;
|
2015-05-24 19:29:52 +00:00
|
|
|
|
2024-04-02 16:49:52 +00:00
|
|
|
// Re-export main components.
|
2024-06-13 20:23:05 +00:00
|
|
|
pub use crate::annotated::{
|
|
|
|
marked_yaml::MarkedYaml, AnnotatedArray, AnnotatedHash, AnnotatedYamlIter, YamlData,
|
|
|
|
};
|
2024-04-02 16:49:52 +00:00
|
|
|
pub use crate::emitter::YamlEmitter;
|
2024-06-13 20:37:56 +00:00
|
|
|
pub use crate::loader::{LoadableYamlNode, YamlLoader};
|
2024-06-10 20:39:13 +00:00
|
|
|
pub use crate::yaml::{Array, Hash, Yaml, YamlIter};
|
2024-04-02 16:49:52 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "encoding")]
|
2024-06-10 16:05:25 +00:00
|
|
|
mod encoding;
|
|
|
|
#[cfg(feature = "encoding")]
|
|
|
|
pub use crate::encoding::{YAMLDecodingTrap, YAMLDecodingTrapFn, YamlDecoder};
|
2024-04-02 16:49:52 +00:00
|
|
|
|
|
|
|
// Re-export `ScanError` as it is used as part of our public API and we want consumers to be able
|
|
|
|
// to inspect it (e.g. perform a `match`). They wouldn't be able without it.
|
|
|
|
pub use saphyr_parser::ScanError;
|
2024-06-13 20:23:05 +00:00
|
|
|
// Re-export [`Marker`] which is used for annotated YAMLs.
|
|
|
|
pub use saphyr_parser::Marker;
|