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 |
#2 in #another
223,826 downloads per month
Used in 159 crates
(46 directly)
14KB
386 lines
serde-transcode
Transcode from one Serde format to another.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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
~110–340KB