How to implement From<AsRef<[U]>> for generic U?

I would just make it a generic constructor:

impl A {
    fn from_bla_slice<U: Bla, T: AsRef<[U]>>(_p: T) -> Self {
        Self {}
    }
}

This way if there's an ambiguity (unlikely) you can resolve it at the call site with an annotation like A::from_bla_slice::<u32, _>(vec![17]), rather than being blocked by the coherence rules.

ETA: also this constructor should almost certainly take &T, not T.

2 Likes