1#[cfg(feature = "axum")]
2pub mod extract;
3
4#[cfg(feature = "quokka-macros")]
5pub use quokka_macros::{FromState, ProvideState};
6
7pub trait FromState<S> {
13 fn from_state(state: &S) -> Self;
14}
15
16pub trait ProvideState<S> {
20 fn provide(&self) -> S;
21}
22
23pub trait ProvideStateRef<S>: ProvideState<S> {
24 fn provide_ref(&self) -> &S;
25
26 fn provide_mut(&mut self) -> &mut S;
27}
28
29pub trait FromStateRef<S>: FromState<S> {
33 fn from_state_ref(state: &S) -> &Self;
34
35 fn from_state_mut(state: &mut S) -> &mut Self;
36}
37
38impl<S, T: FromState<S>> ProvideState<T> for S {
39 fn provide(&self) -> T {
40 T::from_state(self)
41 }
42}
43
44impl<S, T: FromStateRef<S>> ProvideStateRef<T> for S {
45 fn provide_ref(&self) -> &T {
46 T::from_state_ref(self)
47 }
48
49 fn provide_mut(&mut self) -> &mut T {
50 T::from_state_mut(self)
51 }
52}