Add use close to the (De)Serializer usage

This commit is contained in:
Zykino 2022-09-18 10:41:33 +02:00
parent 3ee0a9aee0
commit af86c50311

View File

@ -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) {
match opt.input {
Input::Json => {
use serde_json::Deserializer;
// 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);
}
Input::Ron => {
use ron::Deserializer;
// 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…
let mut buf = vec![];
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);
}
Input::Yaml => {
let deserializer = serde_yaml::Deserializer::from_reader(input);
use serde_yaml::Deserializer;
let deserializer = Deserializer::from_reader(input);
ser(opt, deserializer, output);
}
};
@ -80,13 +86,15 @@ where
{
match opt.output {
Output::Json => {
use serde_json::Serializer;
if opt.pretty {
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();
} else {
let serializer = &mut serde_json::Serializer::new(output);
let serializer = &mut Serializer::new(output);
serde_transcode::transcode(deserializer, serializer).unwrap();
};
@ -95,17 +103,21 @@ where
// serde_transcode::transcode(deserializer, serializer).unwrap();
}
Output::Ron => {
use ron::Serializer;
let mut pretty_config = None;
if opt.pretty {
let pretty = ron::ser::PrettyConfig::new().indentor("\t".to_owned());
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();
}
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();
}