util/error: implement From for Error

This commit is contained in:
meh 2015-05-16 14:44:48 +02:00
parent 7f6d694a7d
commit 8bdb50ebaf

View File

@ -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<Option<[i8; AV_ERROR_MAX_STRING_SIZE as usize]>>,
@ -17,6 +18,12 @@ impl Error {
}
}
impl From<c_int> 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))