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

#70 in Encoding

Download history 75638/week @ 2024-07-30 50861/week @ 2024-08-06 62434/week @ 2024-08-13 82101/week @ 2024-08-20 48906/week @ 2024-08-27 59608/week @ 2024-09-03 51955/week @ 2024-09-10 52492/week @ 2024-09-17 57246/week @ 2024-09-24 63445/week @ 2024-10-01 44874/week @ 2024-10-08 63712/week @ 2024-10-15 59369/week @ 2024-10-22 67106/week @ 2024-10-29 53585/week @ 2024-11-05 67243/week @ 2024-11-12

259,039 downloads per month
Used in 162 crates (48 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

~100–325KB