Skip to content

Commit 396cab2

Browse files
committed
Implemented Error trait for PyErr
1 parent 97c3eb8 commit 396cab2

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/.err.rs.swp

28 KB
Binary file not shown.

src/err.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use std::ptr;
2828
use libc::c_char;
2929
use conversion::ToPyObject;
3030
use std::ffi::CString;
31+
use std::error::Error;
32+
use std::fmt;
3133

3234
/**
3335
Defines a new exception type.
@@ -394,6 +396,21 @@ impl <'p> std::convert::From<PythonObjectDowncastError<'p>> for PyErr {
394396
}
395397
}
396398

399+
impl Error for PyErr {
400+
401+
fn description(&self) -> &str {
402+
"Error originating from the rust-cpython bindings."
403+
}
404+
405+
}
406+
407+
impl fmt::Display for PyErr {
408+
409+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
410+
write!(f, "PyErr: ptype {:?} pvalue {:?}", self.ptype, self.pvalue)
411+
}
412+
}
413+
397414
/// Construct PyObject from the result of a Python FFI call that returns a new reference (owned pointer).
398415
/// Returns `Err(PyErr)` if the pointer is `null`.
399416
/// Unsafe because the pointer might be invalid.

0 commit comments

Comments
 (0)