Merge pull request #3650 from davidhewitt/float2
implement `PyFloatMethods`
This commit is contained in:
commit
d1b4b9e7d4
|
@ -26,4 +26,5 @@ pub use crate::wrap_pyfunction;
|
|||
// Expected to become public API in 0.21
|
||||
// pub(crate) use crate::instance::Py2; // Will be stabilized with a different name
|
||||
// pub(crate) use crate::types::any::PyAnyMethods;
|
||||
// pub(crate) use crate::types::float::PyFloatMethods;
|
||||
// pub(crate) use crate::types::sequence::PySequenceMethods;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#[cfg(feature = "experimental-inspect")]
|
||||
use crate::inspect::types::TypeInfo;
|
||||
use crate::{
|
||||
ffi, FromPyObject, IntoPy, PyAny, PyErr, PyNativeType, PyObject, PyResult, Python, ToPyObject,
|
||||
ffi, instance::Py2, FromPyObject, IntoPy, PyAny, PyErr, PyNativeType, PyObject, PyResult,
|
||||
Python, ToPyObject,
|
||||
};
|
||||
use std::os::raw::c_double;
|
||||
|
||||
|
@ -28,6 +29,23 @@ impl PyFloat {
|
|||
|
||||
/// Gets the value of this float.
|
||||
pub fn value(&self) -> c_double {
|
||||
Py2::borrowed_from_gil_ref(&self).value()
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of functionality for [`PyFloat`].
|
||||
///
|
||||
/// These methods are defined for the `Py2<'py, PyFloat>` smart pointer, so to use method call
|
||||
/// syntax these methods are separated into a trait, because stable Rust does not yet support
|
||||
/// `arbitrary_self_types`.
|
||||
#[doc(alias = "PyFloat")]
|
||||
pub trait PyFloatMethods<'py> {
|
||||
/// Gets the value of this float.
|
||||
fn value(&self) -> c_double;
|
||||
}
|
||||
|
||||
impl<'py> PyFloatMethods<'py> for Py2<'py, PyFloat> {
|
||||
fn value(&self) -> c_double {
|
||||
#[cfg(not(Py_LIMITED_API))]
|
||||
unsafe {
|
||||
// Safety: self is PyFloat object
|
|
@ -17,7 +17,7 @@ pub use self::dict::{IntoPyDict, PyDict};
|
|||
#[cfg(not(PyPy))]
|
||||
pub use self::dict::{PyDictItems, PyDictKeys, PyDictValues};
|
||||
pub use self::ellipsis::PyEllipsis;
|
||||
pub use self::floatob::PyFloat;
|
||||
pub use self::float::PyFloat;
|
||||
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))]
|
||||
pub use self::frame::PyFrame;
|
||||
pub use self::frozenset::{PyFrozenSet, PyFrozenSetBuilder};
|
||||
|
@ -281,7 +281,7 @@ mod complex;
|
|||
mod datetime;
|
||||
mod dict;
|
||||
mod ellipsis;
|
||||
mod floatob;
|
||||
pub(crate) mod float;
|
||||
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))]
|
||||
mod frame;
|
||||
mod frozenset;
|
||||
|
|
Loading…
Reference in New Issue