The Affix State middleware is used to add shared data to the Depot.
To use the Affix State feature, you need to enable the affix-state
feature in Cargo.toml.
Affix State provides a simple way to share data during request processing. It allows you to:
Framework | Language | State Management Approach |
---|---|---|
Salvo (Affix State) | Rust | Stores and accesses via Depot, supports multiple types |
Axum | Rust | Stores state via Extension, similar but with different usage |
Actix-web | Rust | Shares state using App Data and Web::Data |
Gin | Go | Uses context.Set and context.Get to store/retrieve data |
Echo | Go | Manages shared state with context.Set and context.Get |
Spring | Java | Manages dependencies via ApplicationContext or @Bean annotations |
Quarkus | Java | Uses CDI and dependency injection mechanisms |
Express.js | JavaScript | Stores global state in app.locals or req.app.locals |
Nest.js | JavaScript | Manages shared services via dependency injection system |
Koa.js | JavaScript | Stores request-level state in ctx.state |
The advantage of Affix State lies in its simplicity and flexibility, allowing easy sharing of any type of data across different routes and handlers without excessive boilerplate code.
Example Code