Код: Выделить всё
#[pyclass]
struct Number {
#[pyo3(get, set)]
value: i32,
}
#[pymethods]
impl Number {
#[new]
fn new(value: i32) -> Self {
Number { value }
}
fn __repr__(&self) -> PyResult {
Ok(format!("Number({})", self.value))
}
}
#[pyfunction]
fn increment_1(n: &mut Number>) {
b.value += 1;
}
#[pyfunction]
fn increment_2(n: Bound) {
n.borrow_mut().value += 1;
}
#[pymodule]
fn mod(m: &Bound
Подробнее здесь: [url]https://stackoverflow.com/questions/78989851/regular-reference-vs-bound-in-pyo3[/url]