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.6/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. 13 pub trait FromRef<T> { 14 /// Converts to this type from a reference to the input type. from_ref(input: &T) -> Self15 fn from_ref(input: &T) -> Self; 16 } 17 18 impl<T> FromRef<T> for T 19 where 20 T: Clone, 21 { from_ref(input: &T) -> Self22 fn from_ref(input: &T) -> Self { 23 input.clone() 24 } 25 } 26