0
0

BoundRef<'_, '_, PyType> not implemented

Posted at

エラー

classmethod_wrong_first_argument.stderr
the trait bound `i32: From<BoundRef<'_, '_, PyType>>` is not satisfied

コード

use pyo3::prelude::*;

#[pyclass]
struct MyClass(i32);

#[pymethods]
impl MyClass {
    #[classmethod]
    fn add(a: i32, b: i32) -> i32 {a+b}
}

解決策

// 省略
use pyo3::types::PyType;

impl MyClass {
    #[classmethod]
    // 第1引数をclsとする
    fn add(cls: &Bound<'_, PyType>, a: i32, b: i32) -> i32 {a+b}
}

参考

invalid_pymethods.rs 46行目
及び
invalid_pymethods.stderr 182行目

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0