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]
name = "rusty-value"
version = "0.5.1"
version = "0.6.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/Trivernis/rusty-value"

@ -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<T: RustyValue> RustyValue for Option<T> {
#[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,
}
}
}

Loading…
Cancel
Save