Update rusty_value and change handling of newtypes

pull/3/head
trivernis 2 years ago
parent 54f7d606d1
commit ff65fef3d8
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,6 +1,6 @@
[package] [package]
name = "embed-nu" name = "embed-nu"
version = "0.1.1" version = "0.2.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
repository = "https://github.com/Trivernis/embed-nu" repository = "https://github.com/Trivernis/embed-nu"
@ -15,5 +15,5 @@ nu-engine = "0.69.1"
nu-parser = "0.69.1" nu-parser = "0.69.1"
nu-protocol = "0.69.1" nu-protocol = "0.69.1"
paste = "1.0.9" paste = "1.0.9"
rusty-value = { version = "0.3.0", features = ["derive"] } rusty-value = { version = "0.4.0", features = ["derive"] }
thiserror = "1.0.37" thiserror = "1.0.37"

@ -122,6 +122,7 @@ impl RustyIntoValue for rusty_value::Primitive {
val, val,
span: Span::empty(), span: Span::empty(),
}, },
rusty_value::Primitive::OsString(osstr) => osstr.to_string_lossy().into_value(),
} }
} }
} }
@ -144,11 +145,20 @@ impl RustyIntoValue for rusty_value::Fields {
} }
} }
rusty_value::Fields::Unnamed(unnamed) => { rusty_value::Fields::Unnamed(unnamed) => {
let vals = unnamed.into_iter().map(|v| v.into_value()).collect(); let mut vals = unnamed
.into_iter()
Value::List { .map(|v| v.into_value())
vals, .collect::<Vec<_>>();
span: Span::empty(),
// newtypes should be handled differently
// and only return the inner value instead of a range of values
if vals.len() == 1 {
vals.pop().unwrap()
} else {
Value::List {
vals,
span: Span::empty(),
}
} }
} }
rusty_value::Fields::Unit => Value::Nothing { rusty_value::Fields::Unit => Value::Nothing {

@ -1,13 +1,14 @@
use embed_nu::IntoValue; use embed_nu::IntoValue;
use nu_protocol::Value; use nu_protocol::Value;
use rusty_value::RustyValue; use rusty_value::RustyValue;
use std::mem; use std::{mem, path::PathBuf};
#[derive(RustyValue, Debug, Clone)] #[derive(RustyValue, Debug, Clone)]
pub struct TestStruct { pub struct TestStruct {
foo: String, foo: String,
bar: Vec<String>, bar: Vec<String>,
baz: TestEnum, baz: TestEnum,
path: PathBuf,
} }
#[derive(RustyValue, Debug, Clone)] #[derive(RustyValue, Debug, Clone)]
@ -28,8 +29,10 @@ impl TestStruct {
foo: "World".to_string(), foo: "World".to_string(),
bar: vec![], bar: vec![],
baz: TestEnum::Empty, baz: TestEnum::Empty,
path: PathBuf::from("/tmp"),
}), }),
}, },
path: PathBuf::from("/"),
} }
} }
} }

Loading…
Cancel
Save