Struct pyo3::types::function::PyCFunction
source · #[repr(transparent)]pub struct PyCFunction(PyAny);
Expand description
Represents a builtin Python function object.
Tuple Fields§
§0: PyAny
Implementations§
source§impl PyCFunction
impl PyCFunction
#[doc(hidden)] pub const _PYO3_DEF: AddTypeToModule<Self> = _
source§impl PyCFunction
impl PyCFunction
sourcepub fn new_with_keywords_bound<'py>(
py: Python<'py>,
fun: PyCFunctionWithKeywords,
name: &'static str,
doc: &'static str,
module: Option<&Bound<'py, PyModule>>
) -> PyResult<Bound<'py, Self>>
pub fn new_with_keywords_bound<'py>( py: Python<'py>, fun: PyCFunctionWithKeywords, name: &'static str, doc: &'static str, module: Option<&Bound<'py, PyModule>> ) -> PyResult<Bound<'py, Self>>
Create a new built-in function with keywords (*args and/or **kwargs).
sourcepub fn new_bound<'py>(
py: Python<'py>,
fun: PyCFunction,
name: &'static str,
doc: &'static str,
module: Option<&Bound<'py, PyModule>>
) -> PyResult<Bound<'py, Self>>
pub fn new_bound<'py>( py: Python<'py>, fun: PyCFunction, name: &'static str, doc: &'static str, module: Option<&Bound<'py, PyModule>> ) -> PyResult<Bound<'py, Self>>
Create a new built-in function which takes no arguments.
sourcepub fn new_closure_bound<'py, F, R>(
py: Python<'py>,
name: Option<&'static str>,
doc: Option<&'static str>,
closure: F
) -> PyResult<Bound<'py, Self>>
pub fn new_closure_bound<'py, F, R>( py: Python<'py>, name: Option<&'static str>, doc: Option<&'static str>, closure: F ) -> PyResult<Bound<'py, Self>>
Create a new function from a closure.
§Examples
Python::with_gil(|py| {
let add_one = |args: &Bound<'_, PyTuple>, _kwargs: Option<&Bound<'_, PyDict>>| -> PyResult<_> {
let i = args.extract::<(i64,)>()?.0;
Ok(i+1)
};
let add_one = PyCFunction::new_closure_bound(py, None, None, add_one).unwrap();
py_run!(py, add_one, "assert add_one(42) == 43");
});
#[doc(hidden)] pub fn internal_new<'py>( py: Python<'py>, method_def: &PyMethodDef, module: Option<&Bound<'py, PyModule>> ) -> PyResult<Bound<'py, Self>>
Methods from Deref<Target = PyAny>§
#[doc(hidden)] pub const _PYO3_DEF: AddTypeToModule<Self> = _
Trait Implementations§
source§impl AsPyPointer for PyCFunction
impl AsPyPointer for PyCFunction
source§impl AsRef<PyAny> for PyCFunction
impl AsRef<PyAny> for PyCFunction
source§impl Deref for PyCFunction
impl Deref for PyCFunction
source§impl PyTypeInfo for PyCFunction
impl PyTypeInfo for PyCFunction
source§const NAME: &'static str = "PyCFunction"
const NAME: &'static str = "PyCFunction"
Available on non-crate feature
gil-refs
only.Class name.
source§const MODULE: Option<&'static str> = _
const MODULE: Option<&'static str> = _
Available on non-crate feature
gil-refs
only.Module name, if any.
source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Available on non-crate feature
gil-refs
only.Returns the PyTypeObject instance for this type.
source§fn is_type_of_bound(obj: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(obj: &Bound<'_, PyAny>) -> bool
Available on non-crate feature
gil-refs
only.Checks if
object
is an instance of this type or a subclass of this type.impl DerefToPyAny for PyCFunction
Auto Trait Implementations§
impl !Freeze for PyCFunction
impl !RefUnwindSafe for PyCFunction
impl !Send for PyCFunction
impl !Sync for PyCFunction
impl Unpin for PyCFunction
impl UnwindSafe for PyCFunction
Blanket Implementations§
source§impl<T> AssertNotZeroSized for T
impl<T> AssertNotZeroSized for T
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more