Crate serde_nu[][src]

Expand description

Convert any value implementing serde::Serialize into a nu_protocol::Value using serde_nu::to_value. Compare the below manual implemeentation and the one using serde_nu.

use nu_protocol::{Dictionary, UntaggedValue, Value, Primitive};
use serde::Serialize;

#[derive(Serialize)]
struct MyStruct {
    index: usize,
    name: String,
}

fn manual(s: MyStruct) -> Value {
    let mut dict = Dictionary::default();
    dict.insert(
        "index".into(),
        Value::from(UntaggedValue::Primitive(Primitive::Int(s.index as i64))),
    );
    dict.insert(
        "name".into(),
        Value::from(UntaggedValue::Primitive(Primitive::String(s.name))),
    );

    Value::from(UntaggedValue::Row(dict))
}

fn auto(s: &MyStruct) -> Value {
    serde_nu::to_value(s).unwrap()
}

Enums

Functions

Convenience function that takes an iterator over values and turns them into a Vec<ReturnValue> (all successful). This is necessary for the return signatures of most functions in the nu_plugin::Plugin trait.

Convert any value into a nu_protocol::Value