Closed EFanZh closed 1 year ago
The Type::method
syntax is somewhat poorly supported. Many things don't work because auto-deref and coercions don't happen when you use that syntax.
Adding trait impls to make up for the lack of auto derefs seems like a good solution for that deficiency.
Imo it's worth checking if this can be improved on the language side, e.g. by inserting an anonymous shim function. I don't know if that would be acceptable since it would result in a different Fn type in the iterator adapter.
We discussed this in the libs-api meeting today. We're happy to add this, but it might be worth doing a crater run to check for type inference failures.
Proposal
Problem statement
Currently, we have
From<{&,&mut} [T]>
forVec<T>
whereT: Clone
, I think we can also implementFrom<{&,&mut} [T; N]>
forVec<T>
whereT: Clone
.Motivation, use-cases
Suppose I want to convert an
&[[u32; 4]]
value to aVec<Vec<u32>>
type. Currently, I can write:items.iter().map(|item| item.to_vec()).collect::<Vec<_>>()
;items.iter().copied().map(Vec::from).collect::<Vec<_>>()
;I want to be able to write:
items.iter().map(Vec::from).collect::<Vec<_>>()
;Solution sketches
Implement
From<{&,&mut} [T; N]>
forVec<T>
whereT: Clone
.Links and related work
From<&[T]>
.From<&mut [T]>
.What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.