【发布时间】:2021-09-04 18:05:25
【问题描述】:
我正在寻找有关如何构建一个 Python 包的信息,该包包含一个用 Rust 编写的扩展模块,这两种语言是混合的。我正在将 pyO3 用于 FFI,但似乎找不到有关如何执行此操作的示例。 具体来说:我的 rust 库公开了一种类型,该类型后来被 python 类包装。 只有 python 类应该为以后的用户公开,并且包应该是结构化的,这样它就可以被推送到 PyPI。
例如:
生锈的一面
#[pyclass]
pub struct Point {
x: f64,
y: f64
}
#[pymethods]
impl Point {
#[new]
pub fn new(x: f64, y: f64) -> Self { Self{x, y} }
}
在 python 方面
from ??? import Point
class Points:
points: List[Point]
def __init__(self, points: List[Tuple[float, float]]):
self.points = []
for point in points:
x, y = point
self.points.append(Point(x, y))
我会感谢任何信息、来源、示例等!
【问题讨论】:
-
我认为这可能与 StackOverflow 无关,但 see here.
标签: python rust package ffi pyo3