Fix typos and other minor touchups to guide

* Fix some typos
* Capitalize Rust, acronyms
* Remove some trailing whitespace
This commit is contained in:
Roy Wellington Ⅳ 2018-02-22 22:33:49 -08:00 committed by Vlad-Shcherbina
parent 5dc5c534df
commit 24eee46128
5 changed files with 20 additions and 20 deletions

View File

@ -265,7 +265,7 @@ impl MyClass {
}
```
From python prespective `method2`, in above example, does not accept any arguments.
From python perspective `method2`, in above example, does not accept any arguments.
## Class methods
@ -341,7 +341,7 @@ Each parameter could one of following type:
corresponds to python's `def meth(*, arg1.., arg2=..)`
* args="\*": "args" is var args, corresponds to python's `def meth(*args)`. Type of `args`
parameter has to be `&PyTuple`.
* kwargs="\*\*": "kwargs" is kwyword arguments, corresponds to python's `def meth(**kwargs)`.
* kwargs="\*\*": "kwargs" is keyword arguments, corresponds to python's `def meth(**kwargs)`.
Type of `kwargs` parameter has to be `Option<&PyDict>`.
* 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.
@ -353,10 +353,10 @@ Example:
#[py::methods]
impl MyClass {
#[args(arg1=true, args="*", arg2=10, kwargs="**")]
fn method(&self, arg1: bool, args: &PyTuple, arg2: i32, kwargs: Option<&PyTuple>) -> PyResult<i32> {
#[args(arg1=true, args="*", arg2=10, kwargs="**")]
fn method(&self, arg1: bool, args: &PyTuple, arg2: i32, kwargs: Option<&PyTuple>) -> PyResult<i32> {
Ok(1)
}
}
}
```
@ -381,7 +381,7 @@ To customize object attribute access define following methods:
* `fn __setattr__(&mut self, name: FromPyObject, value: FromPyObject) -> PyResult<()>`
* `fn __delattr__(&mut self, name: FromPyObject) -> PyResult<()>`
Each methods coresponds to python's `self.attr`, `self.attr = value` and `del self.attr` code.
Each methods corresponds to python's `self.attr`, `self.attr = value` and `del self.attr` code.
#### String Conversions

View File

@ -67,7 +67,7 @@ fn main() {
[`IntoPyDictPointer`][IntoPyDictPointer] trait. `HashMap` or `BTreeMap` could be used as
keyword arguments. rust tuple with up to 10 elements where each element is tuple with size 2
could be used as kwargs as well. Or `NoArgs` object can be used to indicate that
no keywords areguments are provided.
no keywords arguments are provided.
```rust,ignore
extern crate pyo3;

View File

@ -49,6 +49,6 @@ hello_rust-1.0-cp27-cp27mu-linux_x86_64.whl hello_rust-1.0-cp36-cp36m-linux
hello_rust-1.0-cp27-cp27mu-manylinux1_x86_64.whl hello_rust-1.0-cp36-cp36m-manylinux1_x86_64.whl
```
The `*-manylinux1_x86_64.whl` files are the `manylinux1` wheels that you can upload to PyPi.
The `*-manylinux1_x86_64.whl` files are the `manylinux1` wheels that you can upload to PyPI.
[setuptools-rust]: https://github.com/PyO3/setuptools-rust

View File

@ -2,7 +2,7 @@
## Define a new exception
You can use the `py_exception!` macro to define a new excetpion type:
You can use the `py_exception!` macro to define a new exception type:
```rust
py_exception!(module, MyError);
@ -93,7 +93,7 @@ fn main() {
}
```
[`Python::is_instance()`](https://pyo3.github.io/pyo3/pyo3/struct.Python.html#method.is_instance) calls the underlaying [`PyType::is_instance`](https://pyo3.github.io/pyo3/pyo3/struct.PyType.html#method.is_instance) method to do the actual work.
[`Python::is_instance()`](https://pyo3.github.io/pyo3/pyo3/struct.Python.html#method.is_instance) calls the underlying [`PyType::is_instance`](https://pyo3.github.io/pyo3/pyo3/struct.PyType.html#method.is_instance) method to do the actual work.
To check the type of an exception, you can simply do:
@ -110,7 +110,7 @@ A [`PyErr`](https://pyo3.github.io/pyo3/pyo3/struct.PyErr.html) represents a Pyt
Errors within the `PyO3` library are also exposed as Python exceptions.
PyO3 library handles python exception in two stages. During first stage `PyErr` instance get
created. At this stage python gil is not required. During second stage, actual python
created. At this stage python GIL is not required. During second stage, actual python
exception instance get crated and set to python interpreter.
In simple case, for custom errors support implementation of `std::convert::From<T>` trait

View File

@ -96,7 +96,7 @@ fn init_mod(py: Python, m: &PyModule) -> PyResult<()> {
Ok(())
}
// logic implemented as a normal rust function
// logic implemented as a normal Rust function
fn sum_as_string(a:i64, b:i64) -> String {
format!("{}", a + b).to_string()
}
@ -125,19 +125,19 @@ You obtain a [`Python`](https://pyo3.github.io/pyo3/pyo3/struct.Python.html) ins
by acquiring the GIL, and have to pass it into some operations that call into the Python runtime.
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.
All apis are available through references. Lifetimes of python object's references are
disallowed because any access to python runtime has to be protected by GIL.
All APIs are available through references. Lifetimes of python object's references are
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.
Both implements `Send` and `Sync` traits and maintain python object's reference count.
* [`PyObject`](https://pyo3.github.io/pyo3/pyo3/struct.PyObject.html) is general purpose
type. It does not maintain type of the referenced object. It provides helper methods
for extracing rust values and casting to specific python object type.
* [`Py<T>`](https://pyo3.github.io/pyo3/pyo3/struct.Py.html) represents a reference to a
concrete python object `T`.
type. It does not maintain type of the referenced object. It provides helper methods
for extracting Rust values and casting to specific python object type.
* [`Py<T>`](https://pyo3.github.io/pyo3/pyo3/struct.Py.html) represents a reference to a
concrete python object `T`.
To upgrade to a reference [`AsPyRef`](https://pyo3.github.io/pyo3/pyo3/trait.AsPyRef.html)
trait can be used.