From a00314d1082c1c195edef09d5883fc826f0bab8a Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Tue, 15 Oct 2019 20:44:19 +0100 Subject: [PATCH] Refine error API --- implementations/rust/Cargo.toml | 2 +- implementations/rust/src/lib.rs | 8 ++++---- implementations/rust/src/value/codec.rs | 7 ++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/implementations/rust/Cargo.toml b/implementations/rust/Cargo.toml index 273eeba..996bde7 100644 --- a/implementations/rust/Cargo.toml +++ b/implementations/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "preserves" -version = "0.2.0" +version = "0.2.1" authors = ["Tony Garnock-Jones "] edition = "2018" description = "Implementation of the Preserves serialization format via serde." diff --git a/implementations/rust/src/lib.rs b/implementations/rust/src/lib.rs index d15bd24..ee5f9f6 100644 --- a/implementations/rust/src/lib.rs +++ b/implementations/rust/src/lib.rs @@ -211,7 +211,7 @@ mod decoder_tests { #[cfg(test)] mod samples_tests { use crate::symbol::Symbol; - use crate::value::{Codec, Decoder, codec}; + use crate::value::{Codec, Decoder, decoder::Error}; use crate::value::{Value, PlainValue, Map}; use crate::value::DecodePlaceholderMap; use crate::value::to_value; @@ -237,7 +237,7 @@ mod samples_tests { DecodeShort(#[serde(with = "serde_bytes")] Vec), } - #[test] fn run() -> codec::Result<()> { + #[test] fn run() -> std::io::Result<()> { let mut fh = std::fs::File::open("../../tests/samples.bin").unwrap(); let mut d = Decoder::<_, PlainValue>::new(&mut fh, None); let tests: TestCases = from_value(&d.next().unwrap()).unwrap(); @@ -270,14 +270,14 @@ mod samples_tests { TestCase::DecodeError(ref bin) => { match codec.decode(&mut &bin[..]) { Ok(_) => panic!("Unexpected success"), - Err(codec::Error::Syntax(_)) => (), + Err(Error::Syntax(_)) => (), Err(e) => panic!("Unexpected error {:?}", e), } } TestCase::DecodeShort(ref bin) => { match codec.decode(&mut &bin[..]) { Ok(_) => panic!("Unexpected success"), - Err(codec::Error::Eof) => (), + Err(Error::Eof) => (), Err(e) => panic!("Unexpected error {:?}", e), } } diff --git a/implementations/rust/src/value/codec.rs b/implementations/rust/src/value/codec.rs index 4a9d121..bb5d39e 100644 --- a/implementations/rust/src/value/codec.rs +++ b/implementations/rust/src/value/codec.rs @@ -3,9 +3,6 @@ use decoder::{Decoder, DecodePlaceholderMap}; use encoder::{Encoder, EncodePlaceholderMap}; use std::io::{Read, Write}; -pub type Error = decoder::Error; -pub type Result = decoder::Result; - pub struct Codec { pub decode_placeholders: Option>, pub encode_placeholders: Option>, @@ -29,11 +26,11 @@ impl Codec { Encoder::new(write, self.encode_placeholders.as_ref()) } - pub fn decode<'r, R: Read>(&self, read: &'r mut R) -> Result { + pub fn decode<'r, R: Read>(&self, read: &'r mut R) -> decoder::Result { self.decoder(read).next() } - pub fn encode_bytes(&self, v: &N) -> Result> { + pub fn encode_bytes(&self, v: &N) -> std::io::Result> { let mut buf: Vec = Vec::new(); self.encoder(&mut buf).write(v)?; Ok(buf)