blueprint_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 [`Context`] to extract "subcontexts" from a reference to main application
4/// state.
5///
6/// See [`Context`] for more details on how library authors should use this trait.
7///
8/// This trait can be derived using `#[derive(FromRef)]`.
9///
10/// [`Context`]: https://docs.rs/blueprint_sdk/latest/blueprint_sdk/extract/struct.Context.html
11pub trait FromRef<T> {
12    /// Converts to this type from a reference to the input type.
13    fn from_ref(input: &T) -> Self;
14}
15
16impl<T> FromRef<T> for T
17where
18    T: Clone,
19{
20    fn from_ref(input: &T) -> Self {
21        input.clone()
22    }
23}