1pub trait FromRef<T>: Sized {
2 fn from_ref(_: &T) -> Self;
3}
4
5impl<T: Clone, U: From<T>> FromRef<T> for U {
6 #[inline]
7 fn from_ref(val_ref: &T) -> Self {
8 let val = val_ref.clone();
9 Self::from(val)
10 }
11}
12
13pub trait RefInto<T: Sized>: Clone {
14 fn ref_into(&self) -> T;
15}
16
17impl<T, U: Into<T> + Clone> RefInto<T> for U {
18 #[inline]
19 fn ref_into(&self) -> T {
20 let val = self.clone();
21 val.into()
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use crate::prelude::*;
28
29 #[test]
30 #[allow(unused_must_use)]
31 fn from_ref() {
32 let a = 0u8;
33
34 u16::from(a);
35
36 u16::from_ref(&a);
37
38 let mut a = 0u8;
39
40 u16::from_ref(&mut a);
41 }
42
43 }