zl程序教程

您现在的位置是:首页 >  Python

当前栏目

【Rust日报】2021-11-29 Python中调用 Rust

2023-03-20 15:41:33 时间

Python中调用 Rust

PyO3 使从 Python 调用Rust 代码变得很容易。您可以编写一个Rust库,并依赖PyO3和 maturin (PyO3生态系统的一个支持工具)的组合来编译Rust库,并将其直接作为Python模块安装。除此之外,PyO3可以在Python和Rust之间转换类型,还可以通过一组宏方便地将Rust函数导出到Python。

原文链接: http://saidvandeklundert.net/learn/2021-11-18-calling-rust-from-python-using-pyo3/

Rust for linux: 编写安全的抽象和驱动

Rust有一个关键属性,使其成为内核中的第二语言变得非常有趣:它保证不会发生未定义的行为(只要不安全的代码是合理的)。这包括没有 内存释放后内存使用, double free, 数据竞争等等。

原文链接: https://linuxfoundation.org/webinars/rust-for-linux-writing-abstractions-and-drivers/

Poem-openapi 1.0 发布

Poem OpenAPI是一个基于 Poem 的 OpenAPI 服务器端框架。如果你用过FastAPI,它们在使用上是非常相似的。

1.0版简化了一些宏属性,使用起来更加方便。

use poem::{listener::TcpListener, Route, Server};
use poem_openapi::{param::Query, payload::PlainText, OpenApi, OpenApiService};

struct Api;

#[OpenApi]
impl Api {
  #[oai(path = "/hello", method = "get")]
  async fn index(
    &self,
    #[oai(validator(max_length = 32))] name: Query<Option<String>>,
  ) -> PlainText<String> {
    match name.0 {
      Some(name) => PlainText(format!("hello, {}!", name)),
      None => PlainText("hello!".to_string()),
    }
  }
}

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
  let api_service = OpenApiService::new(Api, "Hello World", "1.0")
      .server("http://localhost:3000/api");
  let ui = api_service.swagger_ui();

  Server::new(TcpListener::bind("127.0.0.1:3000"))
    .run(Route::new().nest("/api", api_service).nest("/", ui))
    .await
}

原文链接: https://crates.io/crates/poem-openapi

Life Simulation

Life simulation, 一个 Rust 编写的 模拟器.

生物可以通过突变和自然选择进化。生物有一个简单的基因组,赋予它们独特的特征.

demo地址: https://joelthelion.github.io/life_web/demo/

github地址: https://github.com/joelthelion/life_web

lib.rs: 一个 crates.io的替代品

lib.rs 索引了 Rust的 72,419 个应用。快速,轻量级,可以作为 crates.io 的一个替代品.

lib.rs: https://lib.rs/