add description

This commit is contained in:
Nikolay Kim 2017-05-22 23:53:14 -07:00
parent 5fdad40caa
commit b350e1cfb4
1 changed files with 16 additions and 10 deletions

View File

@ -10,25 +10,23 @@ use callback::AbortOnDrop;
use class::{BaseObject, PyMethodDefType};
/// Trait implemented by Python object types that have a corresponding type object.
pub trait PyTypeObject {
/// Retrieves the type object for this Python object type.
fn type_object(py: Python) -> PyType;
}
/// Trait implemented by object that generated by py::class macro
/// Basic python type information
/// Implementing this trait for custom struct is enough to make it compatible with
/// python object system
pub trait PyTypeInfo {
/// Type of objects to store in PyObject struct
type Type;
/// Size of the PyObject structure
fn size() -> usize;
/// `Type` instance offset inside PyObject structure
fn offset() -> isize;
/// Type name
fn type_name() -> &'static str;
/// PyTypeObject instance for this type
fn type_object() -> &'static mut ffi::PyTypeObject;
}
@ -84,6 +82,14 @@ impl<'a, T> PyTypeInfo for Py<'a, T> where T: PyTypeInfo {
}
/// Trait implemented by Python object types that have a corresponding type object.
pub trait PyTypeObject {
/// Retrieves the type object for this Python object type.
fn type_object(py: Python) -> PyType;
}
impl<T> PyTypeObject for T where T: BaseObject + PyTypeInfo {
#[inline]