I was gonna create a Pyo3 library which implements some RL environments. I had been using Pyo3 for other tasks. I was gonna use also SDL2 rendering, however it gives me an error.
#[pyclass]
pub struct FirstEnv {
pos: f32,
renderer:…
I have a Python function that can be slow, so I need to be able to run that function concurrently. If I were running the Python script directly, I'd simply create multiple threads and so I would be able to easily run that function concurrently. I…
Many python packages have their performance-critical parts written in Rust and binded to python using, e.g. pyo3. Within the same repo, both .py and .rs files residing in different directories, e.g. in Polars, the rust parts are in polars and the…
I'm using a trait to define an associated type.
pub trait SharedType{ type Item; }
There are cases where I need to implement this trait on a reference &T. However, in these situations I'd like to auto-implement SharedType on a wrapper struct
pub…
Let us say I have the following Rust struct which becomes a Python class:
#[pyclass]
struct MyRustClass {
foo: i32
}
#[pymethods]
impl MyRustClass {
#[new]
fn new(foo: i32) {
MyRustClass { foo }
}
}
This class is made…
`I have base class and derived class.
Base class ctor - works and everything ok, Ive added "create" static method on the dereived class ( which has the same exactly code and return value .
For some reason ctor compiles and work and the derived class…
I am using maturin and I am trying to implement the method get_car() for my class.
But using the following code
use pyo3::prelude::*;
#[pyclass]
struct Car {
name: String,
}
#[pyclass]
struct Garage {
cars: Vec,
}
#[pymethods]
impl…
I have a rust struct with which I had implemented python's magic methods __iter__, __next__, and __call__.
#[pyclass(name = "PyNRICContainer")]
#[derive(Debug)]
#[pyo3(text_signature = "(cls, value, values)")]
pub struct PyNRICContainer {
…
Its not like I am not able to return any rust iterators from a python module function using pyo3. The problem is when lifetime doesn't live long enough!
Allow me to explain.
First attempt:
#[pyclass]
struct ItemIterator {
iter: Box
I have a Rust package which is basically a PyO3 extension. In there I have two files, lib.rs, that is creating a python module and doing conversions from and into Rust types, and parsing.rs which is pure Rust code that I'm wrapping. Now the issue I…
I'm using Py03 to build a python module in Rust. I have a class in Rust which accepts a PyAny to refer to an object in Python. As part of the hash function for the rust class, I want to use the Python ID for this object in the hash function in Rust…
I am trying to implement method which uses Pyo3 loads numpy array.
use ndarray::{array, ArrayView, Ix2};
use numpy::PyArray2;
use pyo3::types::IntoPyDict;
use pyo3::{PyResult, Python};
pub fn load_2d_vec<'a>() -> ArrayView<'a, f32, Ix2> {
// …
I am writing a python model for heavy calculations in rust using the pyo3 bindings. However, for a rust struct with a variable containing an empty list I cannot append to that variable in python.
Does anybody know how to do this? See below for a MWE…
I need port some python code in my rust project (calling python from rust).
I am writing an app in rust that in a small part needs to import a module written in python.
This is my project…
If I have a project like this:
project /
__init__.py
src /
lib.rs
Cargo.toml
...
In the python part (__init__.py), I have to import rust code via:
from .project import *
Is there a way to change the name of the submodule used or is there a…