diff --git a/Cargo.toml b/Cargo.toml index b95c8aa..0603da6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "embed-nu" -version = "0.1.1" +version = "0.2.0" edition = "2021" license = "Apache-2.0" repository = "https://github.com/Trivernis/embed-nu" @@ -15,5 +15,5 @@ nu-engine = "0.69.1" nu-parser = "0.69.1" nu-protocol = "0.69.1" paste = "1.0.9" -rusty-value = { version = "0.3.0", features = ["derive"] } +rusty-value = { version = "0.4.0", features = ["derive"] } thiserror = "1.0.37" diff --git a/src/into_value.rs b/src/into_value.rs index 6989a20..52c7db6 100644 --- a/src/into_value.rs +++ b/src/into_value.rs @@ -122,6 +122,7 @@ impl RustyIntoValue for rusty_value::Primitive { val, 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) => { - let vals = unnamed.into_iter().map(|v| v.into_value()).collect(); - - Value::List { - vals, - span: Span::empty(), + let mut vals = unnamed + .into_iter() + .map(|v| v.into_value()) + .collect::>(); + + // 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 { diff --git a/tests/test_value.rs b/tests/test_value.rs index 8d6664d..453ce7f 100644 --- a/tests/test_value.rs +++ b/tests/test_value.rs @@ -1,13 +1,14 @@ use embed_nu::IntoValue; use nu_protocol::Value; use rusty_value::RustyValue; -use std::mem; +use std::{mem, path::PathBuf}; #[derive(RustyValue, Debug, Clone)] pub struct TestStruct { foo: String, bar: Vec, baz: TestEnum, + path: PathBuf, } #[derive(RustyValue, Debug, Clone)] @@ -28,8 +29,10 @@ impl TestStruct { foo: "World".to_string(), bar: vec![], baz: TestEnum::Empty, + path: PathBuf::from("/tmp"), }), }, + path: PathBuf::from("/"), } } }