Generic assist traits, consume self into a reference
| Input | Into<&T> | Into<&mut T> | IntoRef<Out = T> | IntoMut<Out = T> |
| &T | pass | fail | pass | fail |
| &mut T | fail | pass | pass | pass |
Examples
AsRef/AsMut cannot using in owned convert
// compile_fail
// compile_fail
error[E0515]: cannot return value referencing function parameter
it
Use Into to instead, cannot convert &mut T -> &T:
// pass
// compile_fail
error[E0277]: the trait bound
&u32: From<&mut u32>is not satisfied
Use IntoRef to instead:
use IntoRef;
// pass
// pass