I've got a problem a bit more complicated than this. But I think this breaks it down. I have some generic struct, which has three constructors to get a concrete typed struct. They all have the same generic methods, except for the constructors. What…
I'm very, very new to Rust and struggling with it because of my strong weakly typed programming background.
The code below should write data being received from Python via PYO3 into a XLSX worksheet. I just don't know how to handle the last match,…
I am a beginner to Rust and PyO3, I read the PyO3 User Guide and got some information as shown below:
When Rust calls Python, the memory of Python part is allocated in Python heap and is taken care by the Python garbage collector.
When Python calls…
I'm trying to get PyO3 working on my Mac M1 mini. If I follow the steps to get started with PyO3:
$ mkdir string_sum
$ cd string_sum
$ python -m venv .env
$ source .env/bin/activate
$ pip install maturin
I get "rustc...is not installed or not in…
Suppose I have a Rust struct like this
struct X{...}
struct Y{
x:X
}
I'd like to be able to write python code that accesses X through Y
y = Y()
y.x.some_method()
What would be the best way to implement it in PyO3? Currently I made two wrapper…
Based on this I can create a homogeneous Python dictionary.
How can I create a dictionary with mixed-type values, e.g. make this work:
let dict = [ ("num", 8), ("str", "asd") ].into_py_dict(py);
?
Using PyO3, I am able to pass &str and String types from Rust to Python:
#[pyfunction]
fn test_str(py: Python) -> &str {
"this is a &str"
}
#[pyfunction]
fn test_string(py: Python) -> String {
"this is a String".to_string()
}
And Python is…
I'm wondering if anyone has experience with cross-compiling to windows with pyo3 and maturin.
The pyo3 docs say:
Cross compiling PyO3 modules is relatively straightforward and
requires a few pieces of software:
A toolchain for your target. The…
Trying to build modules hierarchy with pyo3 and this code
pub mod types;
pub mod sources;
use pyo3::prelude::*;
use pyo3::wrap_pymodule;
use sources::file::{find_days, read_many, read_one};
#[pymodule]
fn file(_py: Python, m: &PyModule) ->…
I'm trying to implement a vector class in rust for my math library.
#[pyclass]
struct Vec2d {
#[pyo3(get, set)]
x: f64,
#[pyo3(get, set)]
y: f64
}
But I can't figure out how I can overload the standard operators (+, -, *, /)
I…
I have a struct with two methods return_modified_value and modify_value in Rust. return_modified_value uses modify_value. Rust implementation of modify_value doesn't matter because I want to implement this method in class that will inherit after my…
As a learning exercise I'm trying to implement a parameterised decorator function in pyo3 using closures. The pyo3 documentation contains an example of a (non-parameterised) decorator implemented as a class with a __call__ method, and I've built on…
I'm using pyo3 to add some rust to my python project (for performance), and wanted to create a function to make adding submodules easier. My current code:
fn register_submodule(name: &str, python: Python, parent: &PyModule, funcs: Vec>) ->…
I have the following example:
use pyo3::prelude::*;
use std::collections::{HashMap, HashSet};
use std::sync::RwLock;
#[pyclass]
struct Rustex {
map: RwLock>,
contexts: RwLock>,
}
#[pymethods]
impl…