Skip to content

extra::json doesn't support using Encodable to encode straight to a json value #8335

Closed
@huonw

Description

@huonw

If one wants to convert an Encodable type to a Json value, then one has to do something like (i.e. encode as JSON to a string and then parse that string):

let foo = something_to_convert_to_json;

let s = do std::io::with_str_writer |w| {
    foo.encode(&mut extra::json::Encoder(w));
};
let json = match extra::json::from_str(s) {
    Ok(j) => j,
    Err(_) => fail!("Rust output some json it doesn't understand itself.")
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions