From 8bdb50ebaf79cae7bdea4a511c9eecdc9fc82bea Mon Sep 17 00:00:00 2001 From: meh Date: Sat, 16 May 2015 14:44:48 +0200 Subject: [PATCH] util/error: implement From for Error --- src/util/error.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/util/error.rs b/src/util/error.rs index f60a70e..018ca3f 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -1,11 +1,12 @@ -use ffi::*; use std::error; use std::fmt; use std::cell::RefCell; -use libc::c_int; use std::ffi::CStr; use std::str::from_utf8_unchecked; +use libc::c_int; +use ffi::*; + pub struct Error { code: c_int, desc: RefCell>, @@ -17,6 +18,12 @@ impl Error { } } +impl From for Error { + fn from(value: c_int) -> Error { + Error::new(value) + } +} + impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { f.write_str(error::Error::description(self))