doc fixes
This commit is contained in:
parent
cd17b41b88
commit
81f31153aa
|
@ -72,7 +72,7 @@ To declare constructor, you need to define class method and annotate it with `#[
|
||||||
attribute. Only python `__new__` method can be specified, `__init__` is not available.
|
attribute. Only python `__new__` method can be specified, `__init__` is not available.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#[py::method]
|
#[py::methods]
|
||||||
impl MyClass {
|
impl MyClass {
|
||||||
|
|
||||||
#[new]
|
#[new]
|
||||||
|
@ -115,7 +115,7 @@ struct BaseClass {
|
||||||
val1: usize
|
val1: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[py::class]
|
#[py::methods]
|
||||||
impl BaseClass {
|
impl BaseClass {
|
||||||
#[new]
|
#[new]
|
||||||
fn __new__(obj: &PyRawObject) -> PyResult<()> {
|
fn __new__(obj: &PyRawObject) -> PyResult<()> {
|
||||||
|
@ -132,7 +132,7 @@ struct SubClass {
|
||||||
val2: usize
|
val2: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
#[py::class]
|
#[py::methods]
|
||||||
impl SubClass {
|
impl SubClass {
|
||||||
#[new]
|
#[new]
|
||||||
fn __new__(obj: &PyRawObject) -> PyResult<()> {
|
fn __new__(obj: &PyRawObject) -> PyResult<()> {
|
||||||
|
@ -153,7 +153,7 @@ base class.
|
||||||
## Object properties
|
## Object properties
|
||||||
|
|
||||||
Descriptor methods can be defined in
|
Descriptor methods can be defined in
|
||||||
`#[methods]` `impl` block only and has to be annotated with `#[getter]` or `[setter]`
|
`#[py::methods]` `impl` block only and has to be annotated with `#[getter]` or `[setter]`
|
||||||
attributes. i.e.
|
attributes. i.e.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -252,7 +252,7 @@ impl MyClass {
|
||||||
Calls to this methods protected by `GIL`, `&self` or `&mut self` can be used.
|
Calls to this methods protected by `GIL`, `&self` or `&mut self` can be used.
|
||||||
The return type must be `PyResult<T>` for some `T` that implements `IntoPyObject`.
|
The return type must be `PyResult<T>` for some `T` that implements `IntoPyObject`.
|
||||||
|
|
||||||
`Python` parameter can be spefieid as part of method signature, in this case `py` argument
|
`Python` parameter can be specified as part of method signature, in this case `py` argument
|
||||||
get injected by method wrapper. i.e
|
get injected by method wrapper. i.e
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -311,7 +311,7 @@ impl MyClass {
|
||||||
## Callable object
|
## Callable object
|
||||||
|
|
||||||
To specify custom `__call__` method for custom class, call method needs to be annotated
|
To specify custom `__call__` method for custom class, call method needs to be annotated
|
||||||
with `#[call]` attribute. Arguments of the method are speficied same as for instance method.
|
with `#[call]` attribute. Arguments of the method are specified same as for instance method.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
#[py::methods]
|
#[py::methods]
|
||||||
|
@ -331,19 +331,19 @@ impl MyClass {
|
||||||
By default pyo3 library uses function signature to determine which arguments are required.
|
By default pyo3 library uses function signature to determine which arguments are required.
|
||||||
Then it scans incoming `args` parameter and then incoming `kwargs` parameter. If it can not
|
Then it scans incoming `args` parameter and then incoming `kwargs` parameter. If it can not
|
||||||
find all required parameters, it raises `TypeError` exception.
|
find all required parameters, it raises `TypeError` exception.
|
||||||
It is possible to override default bahavior with `#[args(...)]` attribute. `args` attribute
|
It is possible to override default behavior with `#[args(...)]` attribute. `args` attribute
|
||||||
accept comma separated list of parameters in form `attr_name="default value"`. Each parameter
|
accept comma separated list of parameters in form `attr_name="default value"`. Each parameter
|
||||||
has to match method parameter by name.
|
has to match method parameter by name.
|
||||||
|
|
||||||
Each parameter could one of following type:
|
Each parameter could one of following type:
|
||||||
|
|
||||||
* "\*": var arguments separator, each parameter defined after "*" is keyword only paramters.
|
* "\*": var arguments separator, each parameter defined after "*" is keyword only parameters.
|
||||||
coresponds to python's `def meth(*, arg1.., arg2=..)`
|
corresponds to python's `def meth(*, arg1.., arg2=..)`
|
||||||
* args="\*": "args" is var args, coresponds to python's `def meth(*args)`. Type of `args`
|
* args="\*": "args" is var args, corresponds to python's `def meth(*args)`. Type of `args`
|
||||||
parameter has to be `&PyTuple`.
|
parameter has to be `&PyTuple`.
|
||||||
* kwargs="\*\*": "kwargs" is kwyword arguments, coresponds to python's `def meth(**kwargs)`.
|
* kwargs="\*\*": "kwargs" is kwyword arguments, corresponds to python's `def meth(**kwargs)`.
|
||||||
Type of `kwargs` parameter has to be `Option<&PyDict>`.
|
Type of `kwargs` parameter has to be `Option<&PyDict>`.
|
||||||
* arg="Value": arguments with default value. coresponds to python's `def meth(arg=Value)`.
|
* arg="Value": arguments with default value. corresponds to python's `def meth(arg=Value)`.
|
||||||
if `arg` argument is defined after var arguments it is treated as keyword argument.
|
if `arg` argument is defined after var arguments it is treated as keyword argument.
|
||||||
Note that `Value` has to be valid rust code, pyo3 just inserts it into generated
|
Note that `Value` has to be valid rust code, pyo3 just inserts it into generated
|
||||||
code unmodified.
|
code unmodified.
|
||||||
|
|
|
@ -126,7 +126,7 @@ by acquiring the GIL, and have to pass it into some operations that call into th
|
||||||
|
|
||||||
PyO3 library provides wrappers for python native objects. Ownership of python objects are
|
PyO3 library provides wrappers for python native objects. Ownership of python objects are
|
||||||
disallowed because any access to python runtime has to be protected by GIL.
|
disallowed because any access to python runtime has to be protected by GIL.
|
||||||
All apis are available through references. Lifetimes of python object's refereces are
|
All apis are available through references. Lifetimes of python object's references are
|
||||||
bound to GIL lifetime.
|
bound to GIL lifetime.
|
||||||
|
|
||||||
There are two types of pointers that could be stored on rust structs.
|
There are two types of pointers that could be stored on rust structs.
|
||||||
|
|
Loading…
Reference in New Issue