https://github.com/cloudwego/motore
Async middleware abstraction powered by AFIT and RPITIT.
https://github.com/cloudwego/motore
middleware rust
Last synced: about 1 month ago
JSON representation
Async middleware abstraction powered by AFIT and RPITIT.
- Host: GitHub
- URL: https://github.com/cloudwego/motore
- Owner: cloudwego
- License: apache-2.0
- Created: 2022-06-07T06:57:06.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-24T06:13:01.000Z (5 months ago)
- Last Synced: 2025-04-06T21:09:07.597Z (3 months ago)
- Topics: middleware, rust
- Language: Rust
- Homepage: https://crates.io/crates/motore
- Size: 408 KB
- Stars: 256
- Watchers: 12
- Forks: 24
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
- Support: SUPPORT.md
Awesome Lists containing this project
README

[](https://crates.io/crates/motore)
[](https://docs.rs/motore)
[](#license)
[![Build Status][actions-badge]][actions-url][actions-badge]: https://github.com/cloudwego/motore/actions/workflows/ci.yaml/badge.svg
[actions-url]: https://github.com/cloudwego/motore/actionsMotore is an async middleware abstraction powered by AFIT and RPITIT.
Around Motore, we build modular and reusable components for building robust networking clients and servers.
Motore is greatly inspired by [`Tower`][tower].
[tower]: https://github.com/tower-rs/tower
## Overview
Motore uses AFIT and RPITIT to reduce the mental burden of writing asynchronous code, especially to avoid the overhead of `Box` to make people less anxious.
The core abstraciton of Motore is the `Service` trait:
```rust
pub trait Service {
/// Responses given by the service.
type Response;
/// Errors produced by the service.
type Error;/// Process the request and return the response asynchronously.
async fn call(&self, cx: &mut Cx, req: Request) -> Result;
}
```## Getting Started
Combing AFIT and RPITIT together, we can write asynchronous code in a very concise and readable way.
```rust
pub struct Timeout {
inner: S,
duration: Duration,
}impl Service for Timeout
where
Req: 'static + Send,
S: Service + 'static + Send + Sync,
Cx: 'static + Send,
S::Error: Send + Sync + Into,
{
type Response = S::Response;type Error = BoxError;
async fn call(&self, cx: &mut Cx, req: Req) -> Result {
let sleep = tokio::time::sleep(self.duration);
tokio::select! {
r = self.inner.call(cx, req) => {
r.map_err(Into::into)
},
_ = sleep => Err(std::io::Error::new(std::io::ErrorKind::TimedOut, "service time out").into()),
}
}
}
```We also provided the `#[motore::service]` macro to make writing a `Serivce` more async-native:
```rust
use motore::service;pub struct S {
inner: I,
}#[service]
impl Service for S
where
Req: Send + 'static,
I: Service + Send + 'static + Sync,
Cx: Send + 'static,
{
async fn call(&self, cx: &mut Cx, req: Req) -> Result {
self.inner.call(cx, req).await
}
}
```## FAQ
### Where's the `poll_ready`(a.k.a. backpressure)?
https://www.cloudwego.io/docs/volo/faq/#where-did-poll_ready-backpressure-go
## License
Motore is dual-licensed under the MIT license and the Apache License (Version 2.0).
See [LICENSE-MIT](https://github.com/cloudwego/motore/blob/main/LICENSE-MIT) and [LICENSE-APACHE](https://github.com/cloudwego/motore/blob/main/LICENSE-APACHE) for details.
## Credits
We have used some third party components, and we thank them for their work.
For the full list, you may refer to the [CREDITS.md](https://github.com/cloudwego/motore/blob/main/CREDITS.md) file.
## Community
- Email: [[email protected]](mailto:[email protected])
- How to become a member: [COMMUNITY MEMBERSHIP](https://github.com/cloudwego/community/blob/main/COMMUNITY_MEMBERSHIP.md)
- Issues: [Issues](https://github.com/cloudwego/motore/issues)
- Feishu: Scan the QR code below with [Feishu](https://www.feishu.cn/) or [click this link](https://applink.feishu.cn/client/chat/chatter/add_by_link?link_token=a17m50a7-79cd-4ece-b14c-c1586e1aa636) to join our CloudWeGo Motore user group.
![]()