saphyr-serde/saphyr/src/lib.rs
Ethiraric 23c0b3c547 Move load_from_* functions in Yaml.
This would make more sense in user code:
```rs
Yaml::load_from_str("foo"); // Explicit that we're parsing YAML
load_from_str("foo"); // Too implicit, too generic, may be from another
                         lib
```

Plus, this mirrors `MarkedYaml`'s behavior.
2024-07-03 00:55:41 +02:00

71 lines
2.1 KiB
Rust

// Copyright 2015, Yuheng Chen.
// Copyright 2023, Ethiraric.
// See the LICENSE file at the top-level directory of this distribution.
//! YAML 1.2 implementation in pure Rust.
//!
//! # Usage
//!
//! 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`.
//! ```toml
//! [dependencies]
//! saphyr = "0.0.1"
//! ```
//! or by using `cargo add` to get the latest version:
//! ```sh
//! cargo add saphyr
//! ```
//!
//! # Examples
//! Parse a string into `Vec<Yaml>` and then serialize it as a YAML string.
//!
//! ```
//! use saphyr::{Yaml, YamlEmitter};
//!
//! let docs = Yaml::load_from_str("[1, 2, 3]").unwrap();
//! let doc = &docs[0]; // select the first YAML document
//! assert_eq!(doc[0].as_i64().unwrap(), 1); // access elements by index
//!
//! 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
//! ```
//!
//! # Features
//! **Note:** With all features disabled, this crate's MSRV is `1.65.0`.
//!
//! #### `encoding` (_enabled by default_)
//! Enables encoding-aware decoding of Yaml documents.
//!
//! The MSRV for this feature is `1.70.0`.
#![warn(missing_docs, clippy::pedantic)]
#[macro_use]
mod macros;
mod annotated;
mod char_traits;
mod emitter;
mod loader;
mod yaml;
// Re-export main components.
pub use crate::annotated::{
marked_yaml::MarkedYaml, AnnotatedArray, AnnotatedHash, AnnotatedYamlIter, YamlData,
};
pub use crate::emitter::YamlEmitter;
pub use crate::loader::{LoadableYamlNode, YamlLoader};
pub use crate::yaml::{Array, Hash, Yaml, YamlIter};
#[cfg(feature = "encoding")]
mod encoding;
#[cfg(feature = "encoding")]
pub use crate::encoding::{YAMLDecodingTrap, YAMLDecodingTrapFn, YamlDecoder};
// 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;
// Re-export [`Marker`] which is used for annotated YAMLs.
pub use saphyr_parser::Marker;