How to get Deref coercion when using impl Trait
问题 This function returns the first element of a list-like collection. It works for a variety of different list-like types: fn first<T: Copy>(x: impl Deref<Target=[T]>) -> T { x[0] } For example, this compiles and runs: let data: Vec<usize> = vec![3, 4]; assert_eq!(first(data), 3); let data: &[usize] = &[3, 4]; assert_eq!(first(data), 3); let data: Rc<[usize]> = Rc::new([3, 4]); assert_eq!(first(data), 3); This also compiles and runs: fn stub(x: &[usize]) -> usize { first(x) } let data: &[usize;