Closed
Description
I would like the following code to compile:
fn f<S: Into<Vec<u8>> + Clone>(subscripts: &[S]) -> Vec<Vec<u8>> {
subscripts.iter().cloned().map(|s| s.into()).collect()
}
fn main() {
f(&[&b"hi"[..]]); // this works
f(&[b"hi"]); // error: `From<&[u8; 2]>` is not satisfied
}
The first call in main is hard to get right, since leaving out any part of the syntax gives confusing errors (without [..], gives From<&&[u8; 2]>
is not satisfied, without & gives doesn't have a size known at compile-time
).
The second call seems to be the same idea, but doesn't compile since From isn't implemented for array literals.
This can be implemented without trouble on nightly Rust except for the orphan rule: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=21632f9784745afa98663d5e6e471cbb
If someone is willing to mentor I'm happy to turn that playground into a PR :)