#serde #transcode

serde-transcode

Transcode from one Serde format to another

8 releases (4 stable)

Uses old Rust 2015

1.1.1 Jul 10, 2021
1.1.0 Jan 2, 2019
1.0.1 Dec 31, 2018
1.0.0 Apr 20, 2017
0.1.0 Jul 31, 2016

#112 in Encoding

Download history 5371/week @ 2022-06-10 4899/week @ 2022-06-17 4449/week @ 2022-06-24 3957/week @ 2022-07-01 4975/week @ 2022-07-08 6339/week @ 2022-07-15 3953/week @ 2022-07-22 5101/week @ 2022-07-29 4774/week @ 2022-08-05 7438/week @ 2022-08-12 5440/week @ 2022-08-19 7052/week @ 2022-08-26 5319/week @ 2022-09-02 5459/week @ 2022-09-09 6387/week @ 2022-09-16 5961/week @ 2022-09-23

24,654 downloads per month
Used in 74 crates (26 directly)

MIT/Apache

14KB
386 lines

serde-transcode

Build Status

Documentation

Transcode from one Serde format to another.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Transcode from one Serde format to another.

This crate provides functionality to "transcode" from an arbitrary Serde Deserializer to an arbitrary Serde Serializer without needing to collect the entire input into an intermediate form in memory. For example, you could translate a stream of JSON data into a stream of CBOR data, or translate JSON into its pretty-printed form.

Examples

Translate a JSON file to a pretty-printed version.

extern crate serde;
extern crate serde_json;
extern crate serde_transcode;

use serde::Serialize;
use serde_json::{Serializer, Deserializer};
use std::io::{Read, Write, BufReader, BufWriter};
use std::fs::File;

fn main() {
    let reader = BufReader::new(File::open("input.json").unwrap());
    let writer = BufWriter::new(File::create("output.json").unwrap());

    let mut deserializer = Deserializer::from_reader(reader);
    let mut serializer = Serializer::pretty(writer);
    serde_transcode::transcode(&mut deserializer, &mut serializer).unwrap();
    serializer.into_inner().flush().unwrap();
}

Dependencies

~130–255KB