axum_core/extract/from_ref.rs
1/// Used to do reference-to-value conversions thus not consuming the input value.
2///
3/// This is mainly used with [`State`] to extract "substates" from a reference to main application
4/// state.
5///
6/// See [`State`] for more details on how library authors should use this trait.
7///
8/// This trait can be derived using `#[derive(FromRef)]`.
9///
10/// [`State`]: https://docs.rs/axum/0.7/axum/extract/struct.State.html
11// NOTE: This trait is defined in axum-core, even though it is mainly used with `State` which is
12// defined in axum. That allows crate authors to use it when implementing extractors.
13pub trait FromRef<T> {
14 /// Converts to this type from a reference to the input type.
15 fn from_ref(input: &T) -> Self;
16}
17
18impl<T> FromRef<T> for T
19where
20 T: Clone,
21{
22 fn from_ref(input: &T) -> Self {
23 input.clone()
24 }
25}