Tracking issue for string-like AsRef
coverage
#139429
Labels
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Almost all of the implementations of
AsRef
incore
andstd
are for cheap conversions between string-like types. This tracks all of these such implementations and coordinates efforts to expand coverage.Each column represents a type that can be converted to and each column represents a type that can be converted from. In the tables, ✅ marks an existing impl,⚠️ marks an impl that I argue should be added, N/A marks an impl that does not make sense for that pair of types, and N/A? marks an impl that may make sense (via
as_encoded_bytes
). Impls that are from a more generic impl are marked with a footnote.impl AsRef<T> for U
AsRef<str>
AsRef<OsStr>
AsRef<Path>
AsRef<ByteStr>
AsRef<[u8]>
str
String
Cow<'_, str>
Box<str>
Rc<str>
Arc<str>
UniqueRc<str>
std::string::Drain<'_>
OsStr
OsString
Cow<'_, OsStr>
Box<OsStr>
Rc<OsStr>
Arc<OsStr>
UniqueRc<OsStr>
Path
PathBuf
Cow<'_, Path>
Box<Path>
Rc<Path>
Arc<Path>
UniqueRc<Path>
std::path::Component<'_>
std::path::Components<'_>
std::path::Iter<'_>
ByteStr
ByteString
Cow<'_, ByteStr>
Box<ByteStr>
Rc<ByteStr>
Arc<ByteStr>
UniqueRc<ByteStr>
[u8]
[u8; N]
Vec<u8>
Cow<'_, [u8]>
Box<[u8]>
Rc<[u8]>
Arc<[u8]>
UniqueRc<[u8]>
std::slice::Iter<'_, u8>
std::slice::IterMut<'_, u8>
std::vec::IntoIter<u8>
std::vec::Drain<'_, u8>
Simd<u8, N>
Although
CStr
is string-like, itsAsStr
impls do not interact with other string-like types:impl AsRef<CStr> for T
AsRef<CStr>
CStr
CString
Cow<'_, CStr>
Box<CStr>
Rc<CStr>
Arc<CStr>
UniqueRc<CStr>
Additionally, all of the above impls may be used with any number of references:
Steps
These are the steps I plan to break this effort into:
AsRef<OsStr>
forCow<'_, Path>
#139432AsRef<ByteStr>
for[u8]
#139441AsRef<{OsStr, Path}>
forstd::string::Drain<'_>
.AsRef<ByteStr>
up to parity withAsRef<[u8]>
and implementAsRef<[u8]>
forCow<'_, ByteStr>
.AsRef
forBox
,Rc
,Arc
, andUniqueRc
containers on non-self types, as marked in the table.AsRef
implementations for smart pointers #139318@rustbot claim
@rustbot label +T-libs-api
Footnotes
Implemented via
impl<T: ToOwned + ?Sized> AsRef<T> for Cow<'_, T>
↩ ↩2 ↩3 ↩4 ↩5 ↩6Implemented via
impl<T: ?Sized, A: Allocator> AsRef<T> for Box<T, A>
↩ ↩2 ↩3 ↩4 ↩5 ↩6Implemented via
impl<T: ?Sized, A: Allocator> AsRef<T> for Rc<T, A>
↩ ↩2 ↩3 ↩4 ↩5 ↩6Implemented via
impl<T: ?Sized, A: Allocator> AsRef<T> for Arc<T, A>
↩ ↩2 ↩3 ↩4 ↩5 ↩6Implemented via
impl<T: ?Sized, A: Allocator> AsRef<T> for UniqueRc<T, A>
↩ ↩2 ↩3 ↩4 ↩5 ↩6Implemented via
impl<T> AsRef<[T]> for [T]
↩Implemented via
impl<T, const N: usize> AsRef<[T]> for [T; N]
↩Implemented via
impl<T, A: Allocator> AsRef<[T]> for Vec<T, A>
↩Implemented via
impl<T> AsRef<[T]> for std::slice::Iter<'_, T>
↩Implemented via
impl<T> AsRef<[T]> for std::slice::IterMut<'_, T>
↩Implemented via
impl<T, A: Allocator> AsRef<[T]> for std::vec::IntoIter<T, A>
↩Implemented via
impl<T, A: Allocator> AsRef<[T]> for std::vec::Drain<'_, T, A>
↩Implemented via
impl<T: SimdElement, const N: usize> AsRef<[T]> for Simd<T, N> where LaneCount<N>: SupportedLaneCount
↩The text was updated successfully, but these errors were encountered: