Skip to content

Commit

Permalink
Remove all references to serde_yaml and replace them by serde_yaml_ng
Browse files Browse the repository at this point in the history
  • Loading branch information
acatton committed May 3, 2024
1 parent f639eea commit 61b8e7b
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 284 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Serde YAML
==========

[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/serde--yaml-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/serde-yaml)
[<img alt="crates.io" src="https://img.shields.io/crates/v/serde_yaml.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/serde_yaml)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-serde__yaml-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/serde_yaml)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/serde-yaml/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/serde-yaml/actions?query=branch%3Amaster)
[<img alt="github" src="https://img.shields.io/badge/github-acatton/serde--yaml-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/acatton/serde-yaml-ng)
[<img alt="crates.io" src="https://img.shields.io/crates/v/serde_yaml_ng.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/serde_yaml_ng)
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-serde__yaml__ng-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/serde_yaml_ng)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/acatton/serde-yaml-ng/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/acatton/serde-yaml-ng/actions?query=branch%3Amaster)

Rust library for using the [Serde] serialization framework with data in [YAML]
file format.
Expand Down Expand Up @@ -35,35 +35,35 @@ I'll accept pull request if they're reasonable or easy to work with.
```toml
[dependencies]
serde = "1.0"
serde_yaml = "0.9"
serde_yaml_ng = "0.9"
```

Release notes are available under [GitHub releases].

[GitHub releases]: https://github.com/dtolnay/serde-yaml/releases
[GitHub releases]: https://github.com/acatton/serde-yaml-ng/releases

## Using Serde YAML

[API documentation is available in rustdoc form][docs.rs] but the general idea
is:

[docs.rs]: https://docs.rs/serde_yaml
[docs.rs]: https://docs.rs/serde_yaml_ng

```rust
use std::collections::BTreeMap;

fn main() -> Result<(), serde_yaml::Error> {
fn main() -> Result<(), serde_yaml_ng::Error> {
// You have some type.
let mut map = BTreeMap::new();
map.insert("x".to_string(), 1.0);
map.insert("y".to_string(), 2.0);

// Serialize it to a YAML string.
let yaml = serde_yaml::to_string(&map)?;
let yaml = serde_yaml_ng::to_string(&map)?;
assert_eq!(yaml, "x: 1.0\ny: 2.0\n");

// Deserialize it back to a Rust type.
let deserialized_map: BTreeMap<String, f64> = serde_yaml::from_str(&yaml)?;
let deserialized_map: BTreeMap<String, f64> = serde_yaml_ng::from_str(&yaml)?;
assert_eq!(map, deserialized_map);
Ok(())
}
Expand All @@ -75,7 +75,7 @@ defined in your program.
```toml
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
serde_yaml_ng = "0.9"
```

Structs serialize in the obvious way:
Expand All @@ -89,13 +89,13 @@ struct Point {
y: f64,
}

fn main() -> Result<(), serde_yaml::Error> {
fn main() -> Result<(), serde_yaml_ng::Error> {
let point = Point { x: 1.0, y: 2.0 };

let yaml = serde_yaml::to_string(&point)?;
let yaml = serde_yaml_ng::to_string(&point)?;
assert_eq!(yaml, "x: 1.0\ny: 2.0\n");

let deserialized_point: Point = serde_yaml::from_str(&yaml)?;
let deserialized_point: Point = serde_yaml_ng::from_str(&yaml)?;
assert_eq!(point, deserialized_point);
Ok(())
}
Expand All @@ -114,13 +114,13 @@ enum Enum {
Struct { x: f64, y: f64 },
}

fn main() -> Result<(), serde_yaml::Error> {
fn main() -> Result<(), serde_yaml_ng::Error> {
let yaml = "
- !Newtype 1
- !Tuple [0, 0, 0]
- !Struct {x: 1.0, y: 2.0}
";
let values: Vec<Enum> = serde_yaml::from_str(yaml).unwrap();
let values: Vec<Enum> = serde_yaml_ng::from_str(yaml).unwrap();
assert_eq!(values[0], Enum::Newtype(1));
assert_eq!(values[1], Enum::Tuple(0, 0, 0));
assert_eq!(values[2], Enum::Struct { x: 1.0, y: 2.0 });
Expand All @@ -135,7 +135,7 @@ fn main() -> Result<(), serde_yaml::Error> {
x: 1.0
y: 2.0
";
let values: Vec<Enum> = serde_yaml::from_str(yaml).unwrap();
let values: Vec<Enum> = serde_yaml_ng::from_str(yaml).unwrap();
assert_eq!(values[0], Enum::Tuple(0, 0, 0));
assert_eq!(values[1], Enum::Struct { x: 1.0, y: 2.0 });

Expand All @@ -144,7 +144,7 @@ fn main() -> Result<(), serde_yaml::Error> {
- Unit # serialization produces this one
- !Unit
";
let values: Vec<Enum> = serde_yaml::from_str(yaml).unwrap();
let values: Vec<Enum> = serde_yaml_ng::from_str(yaml).unwrap();
assert_eq!(values[0], Enum::Unit);
assert_eq!(values[1], Enum::Unit);

Expand Down
4 changes: 2 additions & 2 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "serde_yaml-fuzz"
name = "serde_yaml_ng-fuzz"
version = "0.0.0"
authors = ["David Tolnay <[email protected]>"]
edition = "2021"
Expand All @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
serde_yaml = { path = ".." }
serde_yaml_ng = { path = ".." }

[[bin]]
name = "fuzz_from_slice"
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_from_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
if data.len() <= 10240 {
_ = serde_yaml::from_slice::<serde_yaml::Value>(data);
_ = serde_yaml_ng::from_slice::<serde_yaml_ng::Value>(data);
}
});
8 changes: 4 additions & 4 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type Result<T, E = Error> = std::result::Result<T, E>;
/// ```
/// use anyhow::Result;
/// use serde::Deserialize;
/// use serde_yaml::Value;
/// use serde_yaml_ng::Value;
///
/// fn main() -> Result<()> {
/// let input = "k: 107\n";
/// let de = serde_yaml::Deserializer::from_str(input);
/// let de = serde_yaml_ng::Deserializer::from_str(input);
/// let value = Value::deserialize(de)?;
/// println!("{:?}", value);
/// Ok(())
Expand All @@ -42,12 +42,12 @@ type Result<T, E = Error> = std::result::Result<T, E>;
/// ```
/// use anyhow::Result;
/// use serde::Deserialize;
/// use serde_yaml::Value;
/// use serde_yaml_ng::Value;
///
/// fn main() -> Result<()> {
/// let input = "---\nk: 107\n...\n---\nj: 106\n";
///
/// for document in serde_yaml::Deserializer::from_str(input) {
/// for document in serde_yaml_ng::Deserializer::from_str(input) {
/// let value = Value::deserialize(document)?;
/// println!("{:?}", value);
/// }
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::Arc;
/// An error that happened serializing or deserializing YAML data.
pub struct Error(Box<ErrorImpl>);

/// Alias for a `Result` with the error type `serde_yaml::Error`.
/// Alias for a `Result` with the error type `serde_yaml_ng::Error`.
pub type Result<T> = result::Result<T, Error>;

#[derive(Debug)]
Expand Down Expand Up @@ -89,10 +89,10 @@ impl Error {
/// # Examples
///
/// ```
/// # use serde_yaml::{Value, Error};
/// # use serde_yaml_ng::{Value, Error};
/// #
/// // The `@` character as the first character makes this invalid yaml
/// let invalid_yaml: Result<Value, Error> = serde_yaml::from_str("@invalid_yaml");
/// let invalid_yaml: Result<Value, Error> = serde_yaml_ng::from_str("@invalid_yaml");
///
/// let location = invalid_yaml.unwrap_err().location().unwrap();
///
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
//! ```
//! use std::collections::BTreeMap;
//!
//! fn main() -> Result<(), serde_yaml::Error> {
//! fn main() -> Result<(), serde_yaml_ng::Error> {
//! // You have some type.
//! let mut map = BTreeMap::new();
//! map.insert("x".to_string(), 1.0);
//! map.insert("y".to_string(), 2.0);
//!
//! // Serialize it to a YAML string.
//! let yaml = serde_yaml::to_string(&map)?;
//! let yaml = serde_yaml_ng::to_string(&map)?;
//! assert_eq!(yaml, "x: 1.0\ny: 2.0\n");
//!
//! // Deserialize it back to a Rust type.
//! let deserialized_map: BTreeMap<String, f64> = serde_yaml::from_str(&yaml)?;
//! let deserialized_map: BTreeMap<String, f64> = serde_yaml_ng::from_str(&yaml)?;
//! assert_eq!(map, deserialized_map);
//! Ok(())
//! }
Expand All @@ -51,13 +51,13 @@
//! y: f64,
//! }
//!
//! fn main() -> Result<(), serde_yaml::Error> {
//! fn main() -> Result<(), serde_yaml_ng::Error> {
//! let point = Point { x: 1.0, y: 2.0 };
//!
//! let yaml = serde_yaml::to_string(&point)?;
//! let yaml = serde_yaml_ng::to_string(&point)?;
//! assert_eq!(yaml, "x: 1.0\ny: 2.0\n");
//!
//! let deserialized_point: Point = serde_yaml::from_str(&yaml)?;
//! let deserialized_point: Point = serde_yaml_ng::from_str(&yaml)?;
//! assert_eq!(point, deserialized_point);
//! Ok(())
//! }
Expand All @@ -77,13 +77,13 @@
//! Struct { x: f64, y: f64 },
//! }
//!
//! fn main() -> Result<(), serde_yaml::Error> {
//! fn main() -> Result<(), serde_yaml_ng::Error> {
//! let yaml = "
//! - !Newtype 1
//! - !Tuple [0, 0, 0]
//! - !Struct {x: 1.0, y: 2.0}
//! ";
//! let values: Vec<Enum> = serde_yaml::from_str(yaml).unwrap();
//! let values: Vec<Enum> = serde_yaml_ng::from_str(yaml).unwrap();
//! assert_eq!(values[0], Enum::Newtype(1));
//! assert_eq!(values[1], Enum::Tuple(0, 0, 0));
//! assert_eq!(values[2], Enum::Struct { x: 1.0, y: 2.0 });
Expand All @@ -98,7 +98,7 @@
//! x: 1.0
//! y: 2.0
//! ";
//! let values: Vec<Enum> = serde_yaml::from_str(yaml).unwrap();
//! let values: Vec<Enum> = serde_yaml_ng::from_str(yaml).unwrap();
//! assert_eq!(values[0], Enum::Tuple(0, 0, 0));
//! assert_eq!(values[1], Enum::Struct { x: 1.0, y: 2.0 });
//!
Expand All @@ -107,7 +107,7 @@
//! - Unit # serialization produces this one
//! - !Unit
//! ";
//! let values: Vec<Enum> = serde_yaml::from_str(yaml).unwrap();
//! let values: Vec<Enum> = serde_yaml_ng::from_str(yaml).unwrap();
//! assert_eq!(values[0], Enum::Unit);
//! assert_eq!(values[1], Enum::Unit);
//!
Expand Down
22 changes: 11 additions & 11 deletions src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fmt::{self, Display};
use std::hash::{Hash, Hasher};
use std::mem;

/// A YAML mapping in which the keys and values are both `serde_yaml::Value`.
/// A YAML mapping in which the keys and values are both `serde_yaml_ng::Value`.
#[derive(Clone, Default, Eq, PartialEq)]
pub struct Mapping {
map: IndexMap<Value, Value>,
Expand Down Expand Up @@ -236,11 +236,11 @@ impl Mapping {
}
}

/// A type that can be used to index into a `serde_yaml::Mapping`. See the
/// A type that can be used to index into a `serde_yaml_ng::Mapping`. See the
/// methods `get`, `get_mut`, `contains_key`, and `remove` of `Value`.
///
/// This trait is sealed and cannot be implemented for types outside of
/// `serde_yaml`.
/// `serde_yaml_ng`.
pub trait Index: private::Sealed {
#[doc(hidden)]
fn is_key_into(&self, v: &Mapping) -> bool;
Expand Down Expand Up @@ -547,7 +547,7 @@ macro_rules! delegate_iterator {
}
}

/// Iterator over `&serde_yaml::Mapping`.
/// Iterator over `&serde_yaml_ng::Mapping`.
pub struct Iter<'a> {
iter: indexmap::map::Iter<'a, Value, Value>,
}
Expand All @@ -565,7 +565,7 @@ impl<'a> IntoIterator for &'a Mapping {
}
}

/// Iterator over `&mut serde_yaml::Mapping`.
/// Iterator over `&mut serde_yaml_ng::Mapping`.
pub struct IterMut<'a> {
iter: indexmap::map::IterMut<'a, Value, Value>,
}
Expand All @@ -583,7 +583,7 @@ impl<'a> IntoIterator for &'a mut Mapping {
}
}

/// Iterator over `serde_yaml::Mapping` by value.
/// Iterator over `serde_yaml_ng::Mapping` by value.
pub struct IntoIter {
iter: indexmap::map::IntoIter<Value, Value>,
}
Expand All @@ -601,35 +601,35 @@ impl IntoIterator for Mapping {
}
}

/// Iterator of the keys of a `&serde_yaml::Mapping`.
/// Iterator of the keys of a `&serde_yaml_ng::Mapping`.
pub struct Keys<'a> {
iter: indexmap::map::Keys<'a, Value, Value>,
}

delegate_iterator!((Keys<'a>) => &'a Value);

/// Iterator of the keys of a `serde_yaml::Mapping`.
/// Iterator of the keys of a `serde_yaml_ng::Mapping`.
pub struct IntoKeys {
iter: indexmap::map::IntoKeys<Value, Value>,
}

delegate_iterator!((IntoKeys) => Value);

/// Iterator of the values of a `&serde_yaml::Mapping`.
/// Iterator of the values of a `&serde_yaml_ng::Mapping`.
pub struct Values<'a> {
iter: indexmap::map::Values<'a, Value, Value>,
}

delegate_iterator!((Values<'a>) => &'a Value);

/// Iterator of the values of a `&mut serde_yaml::Mapping`.
/// Iterator of the values of a `&mut serde_yaml_ng::Mapping`.
pub struct ValuesMut<'a> {
iter: indexmap::map::ValuesMut<'a, Value, Value>,
}

delegate_iterator!((ValuesMut<'a>) => &'a mut Value);

/// Iterator of the values of a `serde_yaml::Mapping`.
/// Iterator of the values of a `serde_yaml_ng::Mapping`.
pub struct IntoValues {
iter: indexmap::map::IntoValues<Value, Value>,
}
Expand Down
Loading

0 comments on commit 61b8e7b

Please sign in to comment.