Add $crate:: prefix in import_exception!

Also change doctest to use Rust 2018 macro includes.
This commit is contained in:
Alexander Niederbühl 2019-01-27 22:42:30 +01:00
parent 20dbf542c7
commit df36292523

View file

@ -51,21 +51,27 @@ macro_rules! impl_exception_boilerplate {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// #[macro_use] extern crate pyo3; ///extern crate pyo3;
/// ///
/// use pyo3::Python; ///use pyo3::import_exception;
/// use pyo3::types::PyDict; ///use pyo3::types::PyDict;
///use pyo3::Python;
///import_exception!(socket, gaierror);
/// ///
/// import_exception!(socket, gaierror); ///fn main() {
/// let gil = Python::acquire_gil();
/// let py = gil.python();
/// let ctx = PyDict::new(py);
/// ///
/// fn main() { /// ctx.set_item("gaierror", py.get_type::<gaierror>()).unwrap();
/// let gil = Python::acquire_gil(); /// py.run(
/// let py = gil.python(); /// "import socket; assert gaierror is socket.gaierror",
/// let ctx = PyDict::new(py); /// None,
/// Some(ctx),
/// )
/// .unwrap();
///}
/// ///
/// ctx.set_item("gaierror", py.get_type::<gaierror>()).unwrap();
/// py.run("import socket; assert gaierror is socket.gaierror", None, Some(ctx)).unwrap();
/// }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! import_exception { macro_rules! import_exception {
@ -73,9 +79,9 @@ macro_rules! import_exception {
#[allow(non_camel_case_types)] // E.g. `socket.herror` #[allow(non_camel_case_types)] // E.g. `socket.herror`
pub struct $name; pub struct $name;
impl_exception_boilerplate!($name); $crate::impl_exception_boilerplate!($name);
import_exception_type_object!($module, $name); $crate::import_exception_type_object!($module, $name);
}; };
} }