Skip to content

Commit f1133ad

Browse files
authored
fix(axum): Expose IntrospectionConfig to facilitate creating Axum substates (#523)
# Problem Can't inject other dependencies while using `IntrospectionState` as the only state in Axum. Embedding `IntrospectionState` in an `AppState` object that includes other dependencies renders `IntrospectedUser` unusable since it would require an implementation for `FromRef<AppState> for IntrospectionConfig` which in its turn not possible due to `IntrospectionConfig` inside `IntrospectionState` not being public/does not have a public getter. # Solution Since `IntrospectionState` is built using `IntrospectionStateBuilder` it doesn't make sense to expose the field directly. A getter makes more sense :) # Usage Example ```rust struct AppState { some_other_dep: String, introspection_state: IntrospectionState, } impl FromRef<AppState> for IntrospectionConfig { fn from_ref(input: &AppState) -> Self { input.introspection_state.config.clone() } } ```
1 parent 96c9333 commit f1133ad

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/axum/introspection/state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ pub struct IntrospectionState {
88
pub(crate) config: IntrospectionConfig,
99
}
1010

11+
impl IntrospectionState {
12+
pub fn config(&self) -> &IntrospectionConfig {
13+
&self.config
14+
}
15+
}
16+
1117
/// Configuration that must be inject into the axum application state. Used by the
1218
/// [IntrospectionStateBuilder](super::IntrospectionStateBuilder). This struct is also used to create the [IntrospectionState](IntrospectionState)
1319
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)