forked from extern/nushell
e06df124ca
* upgrade dependencies num-bigint 0.3.1 -> 0.4.3 bigdecimal-rs 0.2.1 -> bigdecimal 0.3.0 s3hander 0.7 -> 0.7.5 bat 0.18 -> 0.18, default-features = false * upgrade arboard 1.1.0 -> 2.0.1 * in polars use comfy-table instead of prettytable-rs the last release of prettytable-rs was `0.8.0 Sep 27, 2018` and it uses `term 0.5` as a dependency * upgrade dependencies * upgrade trash -> 2.0.1 Co-authored-by: ahkrr <alexhk@protonmail.com> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
README.md |
serde-nu
Convert any value implementing serde::Serialize
into a
nu_protocol::Value
using nu_serde::to_value
. Compare the below manual
implemeentation and the one using nu_serde
.
use nu_protocol::{Dictionary, Primitive, UntaggedValue, Value};
use nu_source::Tag;
use serde::Serialize;
#[derive(Serialize)]
struct MyStruct {
index: usize,
name: String,
}
fn manual(s: MyStruct, tag: Tag) -> Value {
let mut dict = Dictionary::default();
dict.insert(
"index".into(),
Value {
value: UntaggedValue::Primitive(Primitive::Int(s.index as i64)),
tag: tag.clone(),
},
);
dict.insert(
"name".into(),
Value {
value: UntaggedValue::Primitive(Primitive::String(s.name)),
tag: tag.clone(),
},
);
Value {
value: UntaggedValue::Row(dict),
tag,
}
}
fn auto(s: &MyStruct, tag: Tag) -> Value {
nu_serde::to_value(s, tag).unwrap()
}