implement `PyFloatMethods`
This commit is contained in:
parent
79a54cfc05
commit
8bdae345f3
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue