百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

Thruster

> 编程语言
开源

一个基于中间件的快速 Web 框架,使用 Rust 编写

1.1K stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个基于中间件的快速 Web 框架,使用 Rust 编写

Thruster Latest Version Downloads Online

Get started with examples and walkthroughs on our website!

A fast and intuitive rust web framework

Don't have time to read the docs? Check out

  • Why you should use Thruster
  • Why you shouldn't use Thruster (definitely read this one)

✅ Runs in stable ✅ Runs fast ✅ Doesn't use unsafe

Documentation

Features

  • built with async/await in mind
  • hyper compatible
  • ssl ready
  • testable
  • static file serving
  • socketio
  • gRPC, and more experimental non-tonic based gRPC
  • dependency injection

Motivation

Thruster is a web framework that aims for developers to be productive and consistent across projects and teams. Its goals are to be:

  • Performant
  • Simple
  • Intuitive

Thruster also

  • Does not use unsafe
  • Works in stable rust

Fast

Thruster can be run with different server backends and represents a nicely packaged layer over them. This means that it can keep up with the latest and greatest changes from the likes of Hyper, Actix, or even ThrusterServer, a home-grown http engine.

Intuitive

Based on frameworks like Koa, and Express, Thruster aims to be a pleasure to develop with.

Example

To run the example cargo run --example . For example, cargo run --example hello_world and open http://localhost:4321/

Middleware Based

The core parts that make the new async await code work is designating middleware functions with the #[middleware_fn] attribute (which marks the middleware so that it's compatible with the stable futures version that Thruster is built on,) and then the m! macro in the actual routes.

A simple example for using async await is:

…

Error handling

Here's a nice example

…

Testing

Thruster provides an easy test suite to test your endpoints, simply include the testing module as below:

rust
let mut app = App::::new_basic();

...

app.get("/plaintext", m![plaintext]);

...

let result = testing::get(app, "/plaintext");

assert!(result.body == "Hello, World!");

Make your own middleware modules

Middleware is super easy to make! Simply create a function and export it at a module level. Below, you'll see a piece of middleware that allows profiling of requests:

rust
#[middleware_fn]
async fn profiling(
    mut context: C,
    next: MiddlewareNext,
) -> MiddlewareResult {
    let start_time = Instant::now();

    context = next(context).await?;

    let elapsed_time = start_time.elapsed();
    info!("[{}μs] {}", elapsed_time.as_micros(), context.route());

    Ok(context)
}

You might find that you want to allow for more specific data stored on the context, for example, perhaps you want to be able to hydrate query parameters into a hashmap for later use by other middlewares. In order to do this, you can create an additional trait for the context that middlewares downstream must adhere to. Check out the provided query_params middleware for an example.

Other, or Custom Backends

Thruster is capable of just providing the routing layer on top of a server of some sort, for example, in the Hyper snippet above. This can be applied broadly to any backend, as long as the server implements ThrusterServer.

rust
use async_trait::async_trait;

#[async_trait]
pub trait ThrusterServer {
    type Context: Context + Send;
    type Response: Send;
    type Request: RequestWithParams + Send;

    fn new(App) -> Self;
    async fn build(self, host: &str, port: u16);
}

There needs to be:

  • An easy way to create a server.
  • A function to build the server into a future that could be loaded into an async runtime.

Within the build function, the server implementation should:

  • Start up some sort of listener for connections
  • Call let matched = app.resolve_from_method_and_path(, ); (This is providing the actual routing.)
  • Call app.resolve(, matched) (This runs the chained middleware.)

Why you should use Thruster

  • Change your backends at will. Out of the box, Thruster now can be used over: actix-web, hyper, or a custom backend
  • Thruster supports testing from the framework level
  • @trezm gets lonely when no one makes PRs or opens issues.
  • Thruster is more succinct for more middleware-centric concepts -- like a route guard. Take this example in actix to restrict IPs:
…

Here is Thruster:

rust

#[middleware_fn]
async fn ip_guard(mut context: Ctx, next: MiddlewareNext) -> MiddlewareResult {
    if "1.2.3.4".contains(&context.headers().get("Auth-Token").unwrap_or("")) {
        context = next(context).await?;

        Ok(context)
    } else {
        Err(Error::unauthorized_error(context))
    }

}

#[middleware_fn]
async fn ping(mut context: Ctx, _next: MiddlewareNext) -> MiddlewareResult {
    context.body("pong");
    Ok(context)
}

...
    app.get("/ping", m![ip_guard, plaintext]);
...

A bit more direct is nice!

Why you shouldn't use Thruster

  • It's got few maintainers (pretty much just one.)
  • There are other projects that have been far more battle tested. Thruster is in use in production, but nowhere that you'd know or that matters.
  • It hasn't been optimized by wicked smarties. @trezm tries his best, but keeps getting distracted by his dog(s).
  • Serously, this framework could be is great, but it definitely hasn't been poked and proded like others. Your help could go a long way to making it more secure and robust, but we might not be there just yet.

If you got this far, thanks for reading! Always feel free to reach out.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rusthacktoberfestrustthrusterthruster-rs

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言