add prelude mod

This commit is contained in:
Nikolay Kim 2017-07-31 10:42:55 -07:00
parent 325070f6c9
commit c44e23f4b9
8 changed files with 35 additions and 8 deletions

View File

@ -14,6 +14,9 @@ Changes
* Added `self.__dict__` supoort #68
* Added `pyo3::prelude` module #70
0.1.0 (07-23-2017)
^^^^^^^^^^^^^^^^^^

View File

@ -78,7 +78,7 @@ features = ["extension-module"]
#![feature(proc_macro, specialization)]
extern crate pyo3;
use pyo3::{py, PyResult, Python, PyModule};
use pyo3::prelude::*;
// add bindings to the generated python module
// N.B: names: "librust2py" must be the name of the `.so` or `.pyd` file

View File

@ -8,7 +8,7 @@ use std::fs::File;
use std::io::prelude::*;
use rayon::prelude::*;
use pyo3::*;
use pyo3::prelude::*;
#[py::class]
struct Words {

View File

@ -8,7 +8,7 @@ use std::fs::File;
use std::io::prelude::*;
use rayon::prelude::*;
use pyo3::{py, PyResult, Python, PyModule};
use pyo3::prelude::*;
fn matches(word: &str, search: &str) -> bool {
let mut search = search.chars();

View File

@ -16,7 +16,7 @@ extern crate pyo3;
To define python custom class, rust struct needs to be annotated with `#[py::class]` attribute.
```rust
use pyo3::*;
use pyo3::prelude::*;
#[py::class]
struct MyClass {

View File

@ -66,7 +66,7 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident,
impl _pyo3::ToBorrowedObject for #cls {
#[inline]
fn with_borrowed_ptr<F, R>(&self, _py: _pyo3::Python, f: F) -> R
where F: FnOnce(*mut ffi::PyObject) -> R
where F: FnOnce(*mut _pyo3::ffi::PyObject) -> R
{
f(self.as_ptr())
}
@ -80,7 +80,7 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident,
impl<'a> _pyo3::ToBorrowedObject for &'a mut #cls {
#[inline]
fn with_borrowed_ptr<F, R>(&self, _py: _pyo3::Python, f: F) -> R
where F: FnOnce(*mut ffi::PyObject) -> R
where F: FnOnce(*mut _pyo3::ffi::PyObject) -> R
{
f(self.as_ptr())
}
@ -93,10 +93,10 @@ fn impl_class(cls: &syn::Ident, base: &syn::Ident,
}
impl _pyo3::ToPyPointer for #cls {
#[inline]
fn as_ptr(&self) -> *mut ffi::PyObject {
fn as_ptr(&self) -> *mut _pyo3::ffi::PyObject {
unsafe {
{self as *const _ as *mut u8}
.offset(-<#cls as _pyo3::typeob::PyTypeInfo>::OFFSET) as *mut ffi::PyObject
.offset(-<#cls as _pyo3::typeob::PyTypeInfo>::OFFSET) as *mut _pyo3::ffi::PyObject
}
}
}

View File

@ -198,6 +198,7 @@ pub mod typeob;
pub mod argparse;
pub mod buffer;
pub mod freelist;
pub mod prelude;
// re-export for simplicity
#[doc(hidden)]

23
src/prelude.rs Normal file
View File

@ -0,0 +1,23 @@
// Copyright (c) 2017-present PyO3 Project and Contributors
//! The PyO3 Prelude
//!
//! The purpose of this module is to alleviate imports of many common pyo3 traits
//! by adding a glob import to the top of pyo3 heavy modules:
//!
//! ```
//! # #![allow(unused_imports)]
//! use pyo3::prelude::*;
//! ```
pub use super::py;
pub use class::*;
pub use objects::*;
pub use objectprotocol::ObjectProtocol;
pub use object::PyObject;
pub use python::{Python, ToPyPointer, IntoPyPointer};
pub use err::{PyErr, PyErrValue, PyResult, PyDowncastError, PyErrArguments};
pub use pythonrun::GILGuard;
pub use instance::{PyToken, PyObjectWithToken, AsPyRef, Py, PyNativeType};
pub use conversion::{FromPyObject, RefFromPyObject, PyTryFrom, PyTryInto,
ToPyObject, ToBorrowedObject, IntoPyObject, IntoPyTuple};