Skip to content

Commit 13a4c7e

Browse files
committed
Add ToYaml derive macro implementation for value serialization
1 parent 67283cf commit 13a4c7e

File tree

8 files changed

+33
-14
lines changed

8 files changed

+33
-14
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.2
1+
0.8.3

retag.sh

100644100755
File mode changed.

valu3/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "valu3"
3-
version = "0.8.2"
3+
version = "0.8.3"
44
edition = "2021"
55
license = "Apache-2.0"
66
readme = "crates-io.md"
@@ -17,7 +17,7 @@ pest_derive = "2.7.15"
1717
regex = "1.11.1"
1818
chrono = "0.4.39"
1919
serde = { version = "1.0.216", features = ["derive"], optional = true }
20-
valu3-derive = { path = "../valu3_derive", optional = true, version = "0.8.2" }
20+
valu3-derive = { path = "../valu3_derive", optional = true, version = "0.8.3" }
2121
bincode = { version = "1.3.3", optional = true }
2222

2323
[dev-dependencies]

valu3/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Welcome to **Valu3** - the ultimate, flexible, and powerful library for manipulating diverse data types in your Rust projects. Say goodbye to the complexity of handling numbers, strings, arrays, objects, and datetime values. Valu3 is here to make your life easier!
44

55

6-
[![crates.io](https://img.shields.io/crates/v/valu3?label=0.8.2)](https://crates.io/crates/valu3)
7-
[![Documentation](https://docs.rs/valu3/badge.svg?version=0.8.2)](https://docs.rs/valu3/0.8.2)
6+
[![crates.io](https://img.shields.io/crates/v/valu3?label=0.8.3)](https://crates.io/crates/valu3)
7+
[![Documentation](https://docs.rs/valu3/badge.svg?version=0.8.3)](https://docs.rs/valu3/0.8.3)
88
![MSRV](https://img.shields.io/badge/rustc-1.59+-ab6000.svg)
99
![Apache 2.0 licensed](https://img.shields.io/crates/l/actix-web.svg)
10-
[![Dependency Status](https://deps.rs/crate/valu3/0.8.2/status.svg)](https://deps.rs/crate/valu3/0.8.2)
10+
[![Dependency Status](https://deps.rs/crate/valu3/0.8.3/status.svg)](https://deps.rs/crate/valu3/0.8.3)
1111
![Main test](https://github.com/lowcarboncode/valu3/actions/workflows/main-test.yml/badge.svg)
1212
[![codecov](https://codecov.io/gh/lowcarboncode/valu3/branch/master/graph/badge.svg)](https://codecov.io/gh/lowcarboncode/valu3)
1313
![downloads](https://img.shields.io/crates/d/valu3.svg)

valu3_derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "valu3-derive"
3-
version = "0.8.2"
3+
version = "0.8.3"
44
edition = "2021"
55
license = "Apache-2.0"
66
readme = "crates-io.md"

valu3_derive/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Welcome to **Valu3** - the ultimate, flexible, and powerful library for manipulating diverse data types in your Rust projects. Say goodbye to the complexity of handling numbers, strings, arrays, objects, and datetime values. Valu3 is here to make your life easier!
44

55

6-
[![crates.io](https://img.shields.io/crates/v/valu3?label=0.8.2)](https://crates.io/crates/valu3)
7-
[![Documentation](https://docs.rs/valu3/badge.svg?version=0.8.2)](https://docs.rs/valu3/0.8.2)
6+
[![crates.io](https://img.shields.io/crates/v/valu3?label=0.8.3)](https://crates.io/crates/valu3)
7+
[![Documentation](https://docs.rs/valu3/badge.svg?version=0.8.3)](https://docs.rs/valu3/0.8.3)
88
![MSRV](https://img.shields.io/badge/rustc-1.59+-ab6000.svg)
99
![Apache 2.0 licensed](https://img.shields.io/crates/l/actix-web.svg)
10-
[![Dependency Status](https://deps.rs/crate/valu3/0.8.2/status.svg)](https://deps.rs/crate/valu3/0.8.2)
10+
[![Dependency Status](https://deps.rs/crate/valu3/0.8.3/status.svg)](https://deps.rs/crate/valu3/0.8.3)
1111
![Main test](https://github.com/lowcarboncode/valu3/actions/workflows/main-test.yml/badge.svg)
1212
[![codecov](https://codecov.io/gh/lowcarboncode/valu3/branch/master/graph/badge.svg)](https://codecov.io/gh/lowcarboncode/valu3)
1313
![downloads](https://img.shields.io/crates/d/valu3.svg)

valu3_derive/src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
extern crate proc_macro;
22
use proc_macro::TokenStream;
33
use quote::quote;
4-
use syn::{parse_macro_input, Data, DeriveInput, Fields, Generics, Variant};
4+
use syn::{parse_macro_input, Data, DeriveInput, Fields, Generics, Meta, Variant};
55

6-
#[proc_macro_derive(ToValue)]
6+
#[proc_macro_derive(ToValue, attributes(attr))]
77
pub fn to_value_derive(input: TokenStream) -> TokenStream {
88
let input = parse_macro_input!(input as DeriveInput);
99

@@ -222,3 +222,22 @@ pub fn to_json_derive(input: TokenStream) -> TokenStream {
222222

223223
gen.into()
224224
}
225+
226+
#[proc_macro_derive(ToYaml)]
227+
pub fn to_yaml_derive(input: TokenStream) -> TokenStream {
228+
let input = parse_macro_input!(input as DeriveInput);
229+
let name = input.ident;
230+
let generics = input.generics;
231+
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
232+
233+
let expanded = quote! {
234+
impl #impl_generics ToYamlBehavior for #name #ty_generics #where_clause {
235+
fn to_yaml(&self) -> String {
236+
let value = self.to_value();
237+
value.to_yaml()
238+
}
239+
}
240+
};
241+
242+
TokenStream::from(expanded)
243+
}

0 commit comments

Comments
 (0)