Generic slice `replace`

It'd be nice if this were generic:

pub fn replace<P>(&self, from: P, to: &[T]) -> Vec<T>
where
    P: Pattern

very related: