Crates.io | axum_guard_logic |
lib.rs | axum_guard_logic |
version | 0.3.3 |
source | src |
created_at | 2022-08-27 17:21:24.900817 |
updated_at | 2022-12-28 21:24:38.408993 |
description | Compare extracted and expected data at the router layer with logic. |
homepage | |
repository | |
max_upload_size | |
id | 653502 |
size | 31,001 |
https://crates.io/crates/axum_guard_logic
Impl Guard
for T
pub trait Guard {
fn check_guard(&self, expected:&Self) -> bool;
}
Where the values for self are extracted from the request based on FromRequestParts<State> for T
and the values for expected are given inside the layer on the route.
Router::with(state.clone())
.route("/", get(ok))
.layer(
GuardService::new(
state.clone(),
expected.clone()).into_layer()
);
The argument state passed to GuardService::new()
will be the state called
inside the FromRequestParts
implementation on T
You can also nest using AND/OR logic.
Router::new()
.route("/", get(ok))
.layer(
GuardService::new(state.clone(), expected)
.and(
GuardService::new(
other_state.clone(),
other_expected
)
)
.into_layer()
);
Will reject StatusCode::UNAUTHORIZED
when check_guard
returns false.