Struct cpython::PyInt[][src]

pub struct PyInt(_);

Represents a Python int object.

Note that in Python 2.x, int and long are different types. When rust-cpython is compiled for Python 3.x, PyInt and PyLong are aliases for the same type, which corresponds to a Python int.

You can usually avoid directly working with this type by using ToPyObject and extract with the primitive Rust integer types.

Implementations

impl PyInt[src]

pub fn new(py: Python<'_>, val: c_long) -> PyInt[src]

Creates a new Python 2.7 int object.

Note: you might want to call val.to_py_object(py) instead to avoid truncation if the value does not fit into a c_long, and to make your code compatible with Python 3.x.

pub fn value(&self, _py: Python<'_>) -> c_long[src]

Gets the value of this integer.

Warning: PyInt::value() is only supported for Python 2.7 int objects, but not for long objects. In almost all cases, you can avoid the distinction between these types by simply calling obj.extract::<i32>(py).

Trait Implementations

impl<'s> FromPyObject<'s> for PyInt[src]

impl<'s> FromPyObject<'s> for &'s PyInt[src]

impl PythonObject for PyInt[src]

unsafe fn unchecked_downcast_from(obj: PyObject) -> Self[src]

Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.

unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self[src]

Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.

impl PythonObjectWithCheckedDowncast for PyInt[src]

impl PythonObjectWithTypeObject for PyInt[src]

impl ToPyObject for PyInt[src]

Identity conversion: allows using existing PyObject instances where T: ToPyObject is expected.

type ObjectType = PyInt

Auto Trait Implementations

impl RefUnwindSafe for PyInt[src]

impl Send for PyInt[src]

impl Sync for PyInt[src]

impl Unpin for PyInt[src]

impl UnwindSafe for PyInt[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.