I have a simple class annotated with #[pyclass]
#[pyclass]
pub struct A {
...
}
Now I have a function of the form
fn f(slf: Py) -> PyObject{
//... some code here
let output = A{...};
output.to_object() // Error: method…
Recently I have been working on a project that involves generating docx files. Since Rust's docx support is still quite immature, I've decided to use Python's python-docx module via PyO3.
Here's my code so far:
extern crate pyo3;
use…
I have read this answer(How to call Rust async method from Python?) and what I want to do is the opposite of this.
I want to call a Python async function and await it in tokio's runtime. Is it possible?
I have given it some tries but I am facing an…
When we write vanilla rust and we have to pass in an async function as an argument to another function we do the following:
pub f(
test: &dyn Fn(&'a mut String, String, String, TcpStream) -> F,
) where
F: Future
In order to create a pyo3-powered Python class working with a struct that uses generic type, I want to use wrappers that will generate the code needed to not have to do it for every specific type.
I created a macro that generates the code but I need…
I am learning rust and trying to make a very simple python module using pyo3 and maturin. I am having a problem on the rust code though,
Cargo.toml
[package]
name = "lenrs"
version = "0.1.0"
authors = ["matheusfillipe"]
edition =…
Consider the following Rust code:
use pyo3::prelude::*;
fn main() -> PyResult<()>{
let gil = Python::acquire_gil();
let py = gil.python();
let result = py.run("print('it works')", None, None);
if let Err(ref err) = result {
…
The closer option I have found is pyo3, but it isn't clear to me if it adds any extra overhead when compared to the traditional C-extensions.
From here it seems like such C-extension behavior is possible through borrowed objects (I still have to…
So, to give a bit of context: I want to use a foreign (rust) library with python Kivy application for experimental self-educational purposes. I wasn't sure where to start since I never was too deep in compilation process so I decided to try using…
I am using the numpy crate in Rust to work with 2D arrays that come from python. PyArray (https://docs.rs/numpy/0.11.0/numpy/array/struct.PyArray.html) implements a from_vec2() function, which converts a Vec> into a PyArray (2D…
I am writing a python library with a Rust backend using pyo3 and I don't understand why there isn't an error thrown when you call the wrong constructor, I think what I'm saying will make more sense when I show the code.
// vector.rs
use…
I recently came across PyO3 and I have successfully built the example code from PyO3 repo.
Cargo.toml
[package]
name = "string-sum"
version = "0.1.0"
edition = "2018"
[lib]
name = "string_sum"
crate-type = ["cdylib"]
[dependencies.pyo3]
version =…
I am reading .pyc files, and need to be able to unmarshal code objects. When I try to downcast the unmarshalled PyAny to PyCodeObject, I get the following error message:
error[E0277]: the trait bound `pyo3::ffi::code::PyCodeObject:…
I have a binary module made with pyo3 and rust. It is in a directory with a script that imports it. The directory is marked as source root, so that shouldn't be the problem. There are red squiggly marks under the import, but when I run the script,…