From 63e18899b27392a2676962a35a25bc486cfe4283 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 18 Oct 2022 20:09:57 +0200 Subject: [PATCH] Change how Options get serialized Options simply map to None or the given value. --- Cargo.toml | 2 +- src/value_trait.rs | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 762ca81..0e0f897 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [".", "derive"] [package] name = "rusty-value" -version = "0.5.1" +version = "0.6.0" edition = "2021" license = "Apache-2.0" repository = "https://github.com/Trivernis/rusty-value" diff --git a/src/value_trait.rs b/src/value_trait.rs index c49d168..7499873 100644 --- a/src/value_trait.rs +++ b/src/value_trait.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, ffi::OsString, path::PathBuf}; -use crate::{Enum, Fields, Float, HashablePrimitive, HashableValue, Primitive, Struct, Value}; +use crate::{Fields, Float, HashablePrimitive, HashableValue, Primitive, Struct, Value}; pub trait RustyValue { fn into_rusty_value(self) -> Value; @@ -160,12 +160,14 @@ impl RustyValue for f64 { } impl HashableRustyValue for OsString { + #[inline] fn into_hashable_rusty_value(self) -> HashableValue { HashableValue::Primitive(HashablePrimitive::OsString(self)) } } impl RustyValue for PathBuf { + #[inline] fn into_rusty_value(self) -> Value { Value::Struct(Struct { name: String::from("PathBuf"), @@ -175,20 +177,11 @@ impl RustyValue for PathBuf { } impl RustyValue for Option { + #[inline] fn into_rusty_value(self) -> Value { - let name = String::from("Option"); - match self { - Some(val) => Value::Enum(Enum { - name, - variant: String::from("Some"), - fields: Fields::Unnamed(vec![val.into_rusty_value()]), - }), - None => Value::Enum(Enum { - name, - variant: String::from("None"), - fields: Fields::Unit, - }), + Some(val) => val.into_rusty_value(), + None => Value::None, } } }