Change how Options get serialized

Options simply map to None or the given value.
main
trivernis 2 years ago
parent 136ef062c4
commit 63e18899b2
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -3,7 +3,7 @@ members = [".", "derive"]
[package] [package]
name = "rusty-value" name = "rusty-value"
version = "0.5.1" version = "0.6.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
repository = "https://github.com/Trivernis/rusty-value" repository = "https://github.com/Trivernis/rusty-value"

@ -1,6 +1,6 @@
use std::{collections::HashMap, ffi::OsString, path::PathBuf}; 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 { pub trait RustyValue {
fn into_rusty_value(self) -> Value; fn into_rusty_value(self) -> Value;
@ -160,12 +160,14 @@ impl RustyValue for f64 {
} }
impl HashableRustyValue for OsString { impl HashableRustyValue for OsString {
#[inline]
fn into_hashable_rusty_value(self) -> HashableValue { fn into_hashable_rusty_value(self) -> HashableValue {
HashableValue::Primitive(HashablePrimitive::OsString(self)) HashableValue::Primitive(HashablePrimitive::OsString(self))
} }
} }
impl RustyValue for PathBuf { impl RustyValue for PathBuf {
#[inline]
fn into_rusty_value(self) -> Value { fn into_rusty_value(self) -> Value {
Value::Struct(Struct { Value::Struct(Struct {
name: String::from("PathBuf"), name: String::from("PathBuf"),
@ -175,20 +177,11 @@ impl RustyValue for PathBuf {
} }
impl<T: RustyValue> RustyValue for Option<T> { impl<T: RustyValue> RustyValue for Option<T> {
#[inline]
fn into_rusty_value(self) -> Value { fn into_rusty_value(self) -> Value {
let name = String::from("Option");
match self { match self {
Some(val) => Value::Enum(Enum { Some(val) => val.into_rusty_value(),
name, None => Value::None,
variant: String::from("Some"),
fields: Fields::Unnamed(vec![val.into_rusty_value()]),
}),
None => Value::Enum(Enum {
name,
variant: String::from("None"),
fields: Fields::Unit,
}),
} }
} }
} }

Loading…
Cancel
Save