大型 Yew 应用揭晓: 所有的 RillRate 资源均可使用
RillRate是一个将实时网络仪表盘嵌入到你的应用程序中的库。
RillRate 周一发布了前端的所有资源(由Yew制作)!并将许可完全改为Apache-2.0:前端和后端。
你可以在这里看到Yew应用程序的资源:https://github.com/rillrate/rillrate/tree/trunk/pkg-dashboard
它包括2个crate:
- rate-ui -小部件基础和连接代理
- rate-app -仪表盘
原文链接: https://github.com/rillrate/rillrate
Poem 0.8 版本发布
Poem是一个功能齐全且易于使用的web框架,使用Rust编程语言。
use poem::{handler, listener::TcpListener, route, route::get, web::Path, Server};
#[handler]
fn hello(Path(name): Path<String>) -> String {
format!("hello: {}", name)
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let app = route().at("/hello/:name", get(hello));
let listener = TcpListener::bind("127.0.0.1:3000");
let server = Server::new(listener).await?;
server.run(app).await
}
openapi 例子
use poem::{listener::TcpListener, route};
use poem_openapi::{payload::PlainText, OpenApi, OpenApiService};
struct Api;
#[OpenApi]
impl Api {
#[oai(path = "/hello", method = "get")]
async fn index(
&self,
#[oai(name = "name", in = "query")] name: Option<String>,
) -> PlainText<String> {
match name {
Some(name) => PlainText(format!("hello, {}!", name)),
None => PlainText("hello!".to_string()),
}
}
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let listener = TcpListener::bind("127.0.0.1:3000");
let api_service = OpenApiService::new(Api)
.title("Hello World")
.server("http://localhost:3000/api");
let ui = api_service.swagger_ui("http://localhost:3000");
poem::Server::new(listener)
.await?
.run(route().nest("/api", api_service).nest("/", ui))
.await
}
原文链接: https://www.reddit.com/r/rust/comments/q0d588/poem_08_released/
doku: 0.10 发布
Doku是一个框架,可以直接从代码中构建美观的、人类可读的文档;它允许您轻松地为配置文件、HTTP端点等生成文档。
告别陈旧的手写文档——使用Doku,代码就是文档!
use doku::Document;
use serde::Deserialize;
#[derive(Deserialize, Document)]
struct Config {
/// Database's engine
db_engine: DbEngine,
/// Database's host
#[doku(example = "localhost")]
db_host: String,
/// Database's port
#[doku(example = "5432")]
db_port: usize,
}
#[derive(Deserialize, Document)]
enum DbEngine {
#[serde(rename = "pgsql")]
PostgreSQL,
#[serde(rename = "mysql")]
MySQL,
}
fn main() {
println!("{}", doku::to_json::<Config>());
}
结果
{
// Database's engine
"db_engine": "pgsql" | "mysql",
// Database's host
"db_host": "localhost",
// Database's port
"db_port": 5432
}
github 地址: https://github.com/anixe/doku
--
社区学习交流平台订阅:
- Rustcc论坛: 支持rss
- 微信公众号:Rust语言中文社区