mirror of https://github.com/tildeio/helix
implement fmt::Display for Error
This commit is contained in:
parent
37b2f2f3e9
commit
aec4d726e1
|
@ -1,5 +1,5 @@
|
|||
use super::{Class, ToRuby};
|
||||
use std::{any};
|
||||
use std::{any, fmt};
|
||||
use sys::{VALUE, SPRINTF_TO_S, c_string, rb_eRuntimeError, rb_raise};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -43,6 +43,21 @@ impl Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.message {
|
||||
ErrorMessage::Static(c_string) => {
|
||||
use ::std::ffi::CStr;
|
||||
write!(f, "{}", unsafe { CStr::from_ptr(c_string) }.to_str().unwrap())
|
||||
},
|
||||
ErrorMessage::Dynamic(value) => {
|
||||
use super::FromRuby;
|
||||
write!(f, "{}", String::from_ruby_unwrap(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for Error {}
|
||||
unsafe impl Sync for Error {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue