From 72edd1327a4cb70105598cf025f54cb101ad6b87 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 20 Sep 2019 21:42:45 +0100 Subject: [PATCH] From for std::io::Error --- implementations/rust/src/value/decoder.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/implementations/rust/src/value/decoder.rs b/implementations/rust/src/value/decoder.rs index 51aed6b..95e9f44 100644 --- a/implementations/rust/src/value/decoder.rs +++ b/implementations/rust/src/value/decoder.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read, ErrorKind}; use std::convert::TryInto; use std::convert::TryFrom; use crate::value::value::{Value, AValue, Set, Dictionary}; @@ -14,6 +14,16 @@ pub enum Error { Eof, } +impl From for std::io::Error { + fn from(v: Error) -> Self { + match v { + Error::Io(e) => e, + Error::Syntax(msg) => Self::new(ErrorKind::InvalidData, msg), + Error::Eof => Self::new(ErrorKind::UnexpectedEof, "Unexpected EOF"), + } + } +} + impl From for Error { fn from(v: std::io::Error) -> Self { Error::Io(v)