Add use
close to the (De)Serializer usage
This commit is contained in:
parent
3ee0a9aee0
commit
af86c50311
26
src/lib.rs
26
src/lib.rs
@ -55,20 +55,26 @@ pub fn transcode(opt: Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
|||||||
fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
||||||
match opt.input {
|
match opt.input {
|
||||||
Input::Json => {
|
Input::Json => {
|
||||||
|
use serde_json::Deserializer;
|
||||||
|
|
||||||
// NOTE: Apparently serde_json do not implement `Deserializer` on const?
|
// NOTE: Apparently serde_json do not implement `Deserializer` on const?
|
||||||
let mut deserializer = serde_json::Deserializer::from_reader(input);
|
let mut deserializer = Deserializer::from_reader(input);
|
||||||
ser(opt, &mut deserializer, output);
|
ser(opt, &mut deserializer, output);
|
||||||
}
|
}
|
||||||
Input::Ron => {
|
Input::Ron => {
|
||||||
|
use ron::Deserializer;
|
||||||
|
|
||||||
// NOTE: Apparently ron do not implement `Deserializer` on const?
|
// NOTE: Apparently ron do not implement `Deserializer` on const?
|
||||||
// NOTE: Apparently ron do not implement `Deserializer::from_reader` but it can serialise into a writter…
|
// NOTE: Apparently ron do not implement `Deserializer::from_reader` but it can serialise into a writter…
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
let _buf_size = input.read_to_end(&mut buf).unwrap();
|
let _buf_size = input.read_to_end(&mut buf).unwrap();
|
||||||
let mut deserializer = ron::Deserializer::from_bytes(&buf).unwrap();
|
let mut deserializer = Deserializer::from_bytes(&buf).unwrap();
|
||||||
ser(opt, &mut deserializer, output);
|
ser(opt, &mut deserializer, output);
|
||||||
}
|
}
|
||||||
Input::Yaml => {
|
Input::Yaml => {
|
||||||
let deserializer = serde_yaml::Deserializer::from_reader(input);
|
use serde_yaml::Deserializer;
|
||||||
|
|
||||||
|
let deserializer = Deserializer::from_reader(input);
|
||||||
ser(opt, deserializer, output);
|
ser(opt, deserializer, output);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -80,13 +86,15 @@ where
|
|||||||
{
|
{
|
||||||
match opt.output {
|
match opt.output {
|
||||||
Output::Json => {
|
Output::Json => {
|
||||||
|
use serde_json::Serializer;
|
||||||
|
|
||||||
if opt.pretty {
|
if opt.pretty {
|
||||||
let formatter = serde_json::ser::PrettyFormatter::with_indent(b"\t");
|
let formatter = serde_json::ser::PrettyFormatter::with_indent(b"\t");
|
||||||
let serializer = &mut serde_json::Serializer::with_formatter(output, formatter);
|
let serializer = &mut Serializer::with_formatter(output, formatter);
|
||||||
|
|
||||||
serde_transcode::transcode(deserializer, serializer).unwrap();
|
serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
} else {
|
} else {
|
||||||
let serializer = &mut serde_json::Serializer::new(output);
|
let serializer = &mut Serializer::new(output);
|
||||||
|
|
||||||
serde_transcode::transcode(deserializer, serializer).unwrap();
|
serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
};
|
};
|
||||||
@ -95,17 +103,21 @@ where
|
|||||||
// serde_transcode::transcode(deserializer, serializer).unwrap();
|
// serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
}
|
}
|
||||||
Output::Ron => {
|
Output::Ron => {
|
||||||
|
use ron::Serializer;
|
||||||
|
|
||||||
let mut pretty_config = None;
|
let mut pretty_config = None;
|
||||||
if opt.pretty {
|
if opt.pretty {
|
||||||
let pretty = ron::ser::PrettyConfig::new().indentor("\t".to_owned());
|
let pretty = ron::ser::PrettyConfig::new().indentor("\t".to_owned());
|
||||||
pretty_config = Some(pretty);
|
pretty_config = Some(pretty);
|
||||||
}
|
}
|
||||||
let serializer = &mut ron::Serializer::new(output, pretty_config).unwrap();
|
let serializer = &mut Serializer::new(output, pretty_config).unwrap();
|
||||||
|
|
||||||
serde_transcode::transcode(deserializer, serializer).unwrap();
|
serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
}
|
}
|
||||||
Output::Yaml => {
|
Output::Yaml => {
|
||||||
let serializer = &mut serde_yaml::Serializer::new(output);
|
use serde_yaml::Serializer;
|
||||||
|
|
||||||
|
let serializer = &mut Serializer::new(output);
|
||||||
|
|
||||||
serde_transcode::transcode(deserializer, serializer).unwrap();
|
serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user