Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.9 #3

Merged
merged 18 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a792934
v0.0.9
sebastienrousseau May 26, 2024
e29ff84
docs(serde_yml): :bug: fix `lib.rs` and `safe_cstr.rs`
sebastienrousseau May 26, 2024
c1c1736
test(serde_yml): :white_check_mark: add new tests to cover the `Tag` …
sebastienrousseau May 26, 2024
aca417b
fix(serde_yml): :white_check_mark: fix error: redundant slicing of th…
sebastienrousseau May 26, 2024
4e2929b
test(serde_yml): :white_check_mark: add tests for the `Mapping` struc…
sebastienrousseau May 26, 2024
42ccabd
test(serde_yml): :white_check_mark: add missing unit tests for `ser.rs`
sebastienrousseau May 26, 2024
efd937f
refactor(serde_yml): :art: adds backwards compatibility with old YAML…
sebastienrousseau May 26, 2024
08f8fce
chore(serde_yml): :arrow_up: minor dependencies updates
sebastienrousseau May 26, 2024
a74a928
docs(serde_yml): :art: add logo and minor tweaks
sebastienrousseau May 27, 2024
e587159
feat(serde_yml): :art: add unit tests and updated `directory.rs`
sebastienrousseau May 27, 2024
19696b0
feat(serde_yml): 🎨 sorting unit tests for macros
sebastienrousseau May 27, 2024
e7c8a04
fix(serde_yml): :bug: fix error: the borrowed expression implements t…
sebastienrousseau May 27, 2024
7556134
test(serde_yml): :tada: add unit tests for `macro_partialeq_numeric`
sebastienrousseau May 27, 2024
ab30997
test(serde_yml): :white_check_mark: add unit tests for the `macro_rep…
sebastienrousseau May 27, 2024
c5e16cc
test(serde_yml): :white_check_mark: add unit tests for `macro_get_field`
sebastienrousseau May 27, 2024
866e2ae
test(serde_yml): :white_check_mark: add unit tests for `macro_from_nu…
sebastienrousseau May 27, 2024
f559d28
fix(serde_yml): :bug: fix error: approximate value of `f{32, 64}::con…
sebastienrousseau May 27, 2024
900c353
test(serde_yml): :art: reorganising structure of `value` tests
sebastienrousseau May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ name = "serde_yml"
readme = "README.md"
repository = "https://github.com/sebastienrousseau/serde_yml"
rust-version = "1.60"
version = "0.0.8"
version = "0.0.9"
include = [
"/CONTRIBUTING.md",
"/LICENSE-APACHE",
Expand Down Expand Up @@ -44,14 +44,14 @@ libyml = "0.0.1"
log = { version = "0.4.21", features = ["std"] }
memchr = "2.7.2"
ryu = "1.0.18"
serde = { version = "1.0.201", features = ["derive"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
tempfile = "3.10.1"

[dev-dependencies]
anyhow = "1.0.83"
anyhow = "1.0.86"
indoc = "2.0.5"
serde_derive = "1.0.201"
tempfile = "3.10.1"
serde_derive = "1.0.203"

[features]
default = []
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<!-- markdownlint-disable MD033 MD041 -->

<img src="https://kura.pro/serde_yml/images/logos/serde_yml.webp"
alt="Serde YML logo" width="66" align="right" />

<!-- markdownlint-enable MD033 MD041 -->

# Serde YML (a fork of Serde YAML)

[![GitHub][github-badge]][06]
Expand Down Expand Up @@ -34,7 +41,7 @@ and for inspiring this project.
```toml
[dependencies]
serde = "1.0"
serde_yml = "0.0.8"
serde_yml = "0.0.9"
```

Release notes are available under [GitHub releases][04].
Expand Down Expand Up @@ -599,8 +606,8 @@ of helper functions.

## License

Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
Licensed under either of the [Apache License](LICENSE-APACHE) or the
[MIT license](LICENSE-MIT) at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
Expand All @@ -617,8 +624,8 @@ be dual licensed as above, without any additional terms or conditions.
[08]: https://docs.rs/serde_yml
[09]: https://codecov.io/gh/sebastienrousseau/serde_yml
[10]: https://github.com/sebastienrousseau/serde-yml/actions?query=branch%3Amaster
[build-badge]: https://img.shields.io/github/actions/workflow/status/sebastienrousseau/serde_yml/release.yml?branch=master&style=for-the-badge "Build Status"
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/serde_yml?style=for-the-badge&token=Q9KJ6XXL67 "Codecov"
[build-badge]: https://img.shields.io/github/actions/workflow/status/sebastienrousseau/serde_yml/release.yml?branch=master&style=for-the-badge&logo=github "Build Status"
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/serde_yml?style=for-the-badge&token=Q9KJ6XXL67&logo=codecov "Codecov"
[crates-badge]: https://img.shields.io/crates/v/serde_yml.svg?style=for-the-badge&color=fc8d62&logo=rust "Crates.io"
[docs-badge]: https://img.shields.io/badge/docs.rs-serde__yml-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs "Docs.rs"
[github-badge]: https://img.shields.io/badge/github-sebastienrousseau/serde--yml-8da0cb?style=for-the-badge&labelColor=555555&logo=github "GitHub"
2 changes: 1 addition & 1 deletion TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
- **test(serde-yaml)**: Expanded the test suite by adding comprehensive unit tests for the `ser.rs` module. The new tests cover various serialization scenarios, including scalar values, sequences, maps, nested structures, optional fields, and custom serializers.
- Commit: `test(serde-yaml): :white_check_mark: add unit tests for the `ser.rs` module`

**Full Changelog**: https://github.com/sebastienrousseau/serde_yml/commits/v0.0.8
**Full Changelog**: https://github.com/sebastienrousseau/serde_yml/commits/v0.0.9
68 changes: 39 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
//! # Serde YML
//!# Serde YML (a fork of Serde YAML)
//!
//! [![Serde YML Logo](https://kura.pro/serde_yml/images/banners/banner-serde_yml.svg)](https://serde_yml.one "Serde YML: Seamless YAML Serialization for Rust")
//![![GitHub][github-badge]][06]
//![![Crates.io][crates-badge]][07]
//![![Docs.rs][docs-badge]][08]
//![![Codecov][codecov-badge]][09]
//![![Build Status][build-badge]][10]
//!
//! ## Seamless YAML Serialization for [Rust][rust-lang]
//!A Rust library for using the [Serde][01] serialization framework with data in [YAML][05] file format. This project, has been renamed to [Serde YML][00] to avoid confusion with the original Serde YAML crate which is now archived and no longer maintained.
//!
//! [![Crates.io](https://img.shields.io/crates/v/serde_yml.svg?style=for-the-badge&color=success&labelColor=27A006)][crates-io]
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.7-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)][lib-rs]
//! [![License](https://img.shields.io/crates/l/serde_yml.svg?style=for-the-badge&color=007EC6&labelColor=03589B)][license]
//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)][rust-lang]
//!## Credits and Acknowledgements
//!
//!This library is a continuation of the excellent work done by [David Tolnay][03] and the maintainers of the [serde-yaml][02] library.
//!
//!While Serde YML started as a fork of serde-yaml, it has now evolved into a separate library with its own goals and direction in mind and does not intend to replace the original serde-yaml crate.
//!
//!If you are currently using serde-yaml in your projects, we recommend carefully evaluating your requirements and considering the stability and maturity of the original library as well as looking at the features and improvements offered by other YAML libraries in the Rust ecosystem.
//!
//!I would like to express my sincere gratitude to [David Tolnay][03] and the [serde-yaml][02] team for their valuable contributions to the Rust community and for inspiring this project.
//!
//! [Serde YML][serde-yml] is a Rust library that simplifies YAML serialization and deserialization using the popular [Serde][serde] framework. It provides a convenient and efficient way to convert Rust data structures to YAML format and vice versa.
//!
//! ## Features
//!
Expand Down Expand Up @@ -37,7 +45,7 @@
//!
//! ```toml
//! [dependencies]
//! serde_yml = "0.0.7"
//! serde_yml = "0.0.9"
//! ```
//!
//! ## Usage
Expand Down Expand Up @@ -80,20 +88,22 @@
//!
//! The examples cover various scenarios, including serializing and deserializing structs, enums, optional fields, custom structs, and more.
//!
//! ## Best Practices and Common Pitfalls
//!
//! - When serializing large datasets, consider using `serde_yml::to_writer` to write the YAML output directly to a file or a writer instead of keeping the entire serialized string in memory.
//! - Be cautious when deserializing untrusted YAML input, as it may contain unexpected or malicious data. Always validate and handle the deserialized data appropriately.
//! - When working with custom structs or enums, ensure that they implement the necessary Serde traits (`Serialize` and `Deserialize`) for proper serialization and deserialization.
//! - If you encounter any issues or have questions, refer to the library's documentation and examples for guidance. If the problem persists, consider opening an issue on the library's [GitHub repository][repo].
//!
//! ## Credits and Acknowledgements
//!
//! Serde YML draws inspiration from the excellent work done by [David Tolnay][dtolnay] and the maintainers of the [serde-yaml][serde-yaml] library. While Serde YML started as a fork of serde-yaml, it has now evolved into a separate library with its own goals and direction in mind.
//!
//! If you are currently using serde-yaml in your projects, we recommend carefully evaluating your requirements and considering the stability and maturity of the original library before migrating to Serde YML.
//!
//! Finally, we would like to express our sincere gratitude to [David Tolnay][dtolnay] and the [serde-yaml][serde-yaml] team for their valuable contributions to the Rust community and for inspiring this project.
//![00]: https://serdeyml.com
//![01]: https://github.com/serde-rs/serde
//![02]: https://github.com/dtolnay/serde-yaml
//![03]: https://github.com/dtolnay
//![04]: https://github.com/sebastienrousseau/serde_yml/releases
//![05]: https://yaml.org/
//![06]: https://github.com/sebastienrousseau/serde_yml
//![07]: https://crates.io/crates/serde_yml
//![08]: https://docs.rs/serde_yml
//![09]: https://codecov.io/gh/sebastienrousseau/serde_yml
//![10]: https://github.com/sebastienrousseau/serde-yml/actions?query=branch%3Amaster
//![build-badge]: https://img.shields.io/github/actions/workflow/status/sebastienrousseau/serde_yml/release.yml?branch=master&style=for-the-badge "Build Status"
//![codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/serde_yml?style=for-the-badge&token=Q9KJ6XXL67 "Codecov"
//![crates-badge]: https://img.shields.io/crates/v/serde_yml.svg?style=for-the-badge&color=fc8d62&logo=rust "Crates.io"
//![docs-badge]: https://img.shields.io/badge/docs.rs-serde__yml-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs "Docs.rs"
//![github-badge]: https://img.shields.io/badge/github-sebastienrousseau/serde--yml-8da0cb?style=for-the-badge&labelColor=555555&logo=github "GitHub"
//!
//! [serde-yml]: https://serdeyml.com "Serde YML"
//! [serde]: https://github.com/serde-rs/serde
Expand Down Expand Up @@ -123,12 +133,6 @@ pub use crate::value::{
from_value, to_value, Index, Number, Sequence, Value,
}; // Value manipulation functions

/// The `macros` module contains functions for generating macros.
pub mod macros;

/// The `utilities` module contains utility functions for the library.
pub mod utilities;

#[doc(inline)]
pub use crate::mapping::Mapping; // Re-export the Mapping type for YAML mappings

Expand All @@ -141,6 +145,9 @@ pub mod libyml;
/// The `loader` module contains the `Loader` type for YAML loading.
pub mod loader;

/// The `macros` module contains functions for generating macros.
pub mod macros;

/// The `mapping` module contains the `Mapping` type for YAML mappings.
pub mod mapping;

Expand All @@ -153,6 +160,9 @@ pub mod number;
/// The `ser` module contains the library's YAML serializer.
pub mod ser;

/// The `utilities` module contains utility functions for the library.
pub mod utilities;

/// The `value` module contains the `Value` type for YAML values.
pub mod value;

Expand Down
3 changes: 0 additions & 3 deletions src/libyml/safe_cstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use std::{
///
/// This struct implements the `Display` and `std::error::Error` traits, which allows it to be printed and used as an error type.
///
/// # See Also
///
/// * [`CStr`](crate::CStr) - A struct representing a C string.
///
pub struct CStrError;

Expand Down
49 changes: 49 additions & 0 deletions src/macros/macro_get_field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/// Macro to generate a function that retrieves a field value from a JSON file.
///
/// # Arguments
///
/// * `$func_name` - The name of the generated function.
/// * `$deserializer` - The deserializer used to parse the JSON file.
///
/// # Returns
///
/// The generated function returns a `Result` containing the field value as a `String`,
/// or a `Box<dyn std::error::Error>` if an error occurs.
///
#[macro_export]
macro_rules! macro_get_field {
($func_name:ident, $deserializer:expr) => {
/// Reads a file and deserializes its content using the specified
/// deserializer function.
pub fn $func_name(
// The path of the JSON file to read.
file_path: Option<&str>,
// The name of the field to retrieve.
field_name: &str,
) -> Result<String, Box<dyn std::error::Error>> {
file_path.map_or_else(
|| Ok(String::new()),
|file_path| {
let current_dir = env::current_dir()?;
let file_path =
Path::new(&current_dir).join(file_path);
let file_contents =
std::fs::read_to_string(&file_path)?;
let value: serde_json::Value =
$deserializer(file_contents.as_bytes())?;
let field_value = value
.get(field_name)
.ok_or_else(|| {
format!("Field '{}' not found", field_name)
})?
.as_str()
.map(|s| s.to_string())
.unwrap_or_else(|| {
value[field_name].to_string()
});
Ok(field_value)
},
)
}
};
}
51 changes: 0 additions & 51 deletions src/macros/macro_log.rs

This file was deleted.

54 changes: 54 additions & 0 deletions src/macros/macro_replace_placeholder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/// Replaces placeholders in a given line with corresponding values from the provided parameters.
///
/// # Arguments
///
/// * `line` - The line containing placeholders to be replaced.
/// * `params` - The parameters containing values to replace the placeholders.
/// * `$($field:ident),+` - Identifiers representing the fields in `params` to be replaced.
///
/// # Returns
///
/// The line with placeholders replaced by their corresponding values.
///
///
/// # Examples
///
/// ```
/// use serde_yml::macro_replace_placeholder;
//
/// #[derive(Default)]
/// struct Params {
/// field1: Option<&'static str>,
/// field2: Option<&'static str>,
/// }
//
/// let params = Params {
/// field1: Some("value1"),
/// field2: Some("value2"),
/// };
//
/// // Test replacing both fields
/// let line = macro_replace_placeholder!(
/// "Field 1: {field1}, Field 2: {field2}",
/// &params,
/// field1,
/// field2
/// );
/// assert_eq!(line, "Field 1: value1, Field 2: value2");
/// ```
///
#[macro_export]
macro_rules! macro_replace_placeholder {
($line:expr, $params:expr, $($field:ident),+) => {
{
let mut line = $line.to_owned(); // Convert line to owned String
$(
line = line.replace(
concat!("{", stringify!($field), "}"),
&$params.$field.as_deref().unwrap_or(""),
);
)+
line
}
};
}
Loading
Loading