Tracking issue for string-like AsRef coverage (original) (raw)

Almost all of the implementations of AsRef in core and std 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 for U AsRef​ AsRef​ AsRef​ AsRef​ AsRef​<[u8]>
str
String ⚠️
Cow<'_, str> 1 ⚠️ ⚠️ ⚠️ ⚠️
Box 2 ⚠️ ⚠️ ⚠️ ⚠️
Rc 3 ⚠️ ⚠️ ⚠️ ⚠️
Arc 4 ⚠️ ⚠️ ⚠️ ⚠️
UniqueRc 5 ⚠️ ⚠️ ⚠️ ⚠️
std:🧵:Drain<'_> ⚠️ ⚠️ ⚠️
OsStr N/A N/A? N/A?
OsString N/A N/A? N/A?
Cow<'_, OsStr> N/A 1 N/A? N/A?
Box N/A 2 ⚠️ N/A? N/A?
Rc N/A 3 ⚠️ N/A? N/A?
Arc N/A 4 ⚠️ N/A? N/A?
UniqueRc N/A 5 ⚠️ N/A? N/A?
Path N/A N/A? N/A?
PathBuf N/A N/A? N/A?
Cow<'_, Path> N/A ⚠️#139432 1 N/A? N/A?
Box N/A ⚠️ 2 N/A? N/A?
Rc N/A ⚠️ 3 N/A? N/A?
Arc N/A ⚠️ 4 N/A? N/A?
UniqueRc N/A ⚠️ 5 N/A? N/A?
std::path::Component<'_> N/A N/A? N/A?
std::path::Components<'_> N/A N/A? N/A?
std::path::Iter<'_> N/A N/A? N/A?
ByteStr N/A N/A N/A
ByteString N/A N/A N/A
Cow<'_, ByteStr> N/A N/A N/A 1 ⚠️
Box N/A N/A N/A 2 ⚠️
Rc N/A N/A N/A 3 ⚠️
Arc N/A N/A N/A 4 ⚠️
UniqueRc N/A N/A N/A 5 ⚠️
[u8] N/A N/A N/A ⚠️#139441 6
[u8; N] N/A N/A N/A ⚠️ 7
Vec N/A N/A N/A ⚠️ 8
Cow<'_, [u8]> N/A N/A N/A ⚠️ 1
Box<[u8]> N/A N/A N/A ⚠️ 2
Rc<[u8]> N/A N/A N/A ⚠️ 3
Arc<[u8]> N/A N/A N/A ⚠️ 4
UniqueRc<[u8]> N/A N/A N/A ⚠️ 5
std::slice::Iter<'_, u8> N/A N/A N/A ⚠️ 9
std::slice::IterMut<'_, u8> N/A N/A N/A ⚠️ 10
std::vec::IntoIter N/A N/A N/A ⚠️ 11
std::vec::Drain<'_, u8> N/A N/A N/A ⚠️ 12
Simd<u8, N> N/A N/A N/A ⚠️ 13

Although CStr is string-like, its AsStr impls do not interact with other string-like types:

impl AsRef for T AsRef
CStr
CString
Cow<'_, CStr> 1
Box 2
Rc 3
Arc 4
UniqueRc 5

Additionally, all of the above impls may be used with any number of references:

impl<T: AsRef + ?Sized, U: ?Sized> AsRef for &T impl<T: AsRef + ?Sized, U: ?Sized> AsRef for &mut T

Steps

These are the steps I plan to break this effort into:

@rustbot claim

@rustbot label +T-libs-api

  1. Implemented via impl<T: ToOwned + ?Sized> AsRef<T> for Cow<'_, T> ↩2 ↩3 ↩4 ↩5 ↩6
  2. Implemented via impl<T: ?Sized, A: Allocator> AsRef<T> for Box<T, A> ↩2 ↩3 ↩4 ↩5 ↩6
  3. Implemented via impl<T: ?Sized, A: Allocator> AsRef<T> for Rc<T, A> ↩2 ↩3 ↩4 ↩5 ↩6
  4. Implemented via impl<T: ?Sized, A: Allocator> AsRef<T> for Arc<T, A> ↩2 ↩3 ↩4 ↩5 ↩6
  5. Implemented via impl<T: ?Sized, A: Allocator> AsRef<T> for UniqueRc<T, A> ↩2 ↩3 ↩4 ↩5 ↩6
  6. Implemented via impl<T> AsRef<[T]> for [T]
  7. Implemented via impl<T, const N: usize> AsRef<[T]> for [T; N]
  8. Implemented via impl<T, A: Allocator> AsRef<[T]> for Vec<T, A>
  9. Implemented via impl<T> AsRef<[T]> for std::slice::Iter<'_, T>
  10. Implemented via impl<T> AsRef<[T]> for std::slice::IterMut<'_, T>
  11. Implemented via impl<T, A: Allocator> AsRef<[T]> for std::vec::IntoIter<T, A>
  12. Implemented via impl<T, A: Allocator> AsRef<[T]> for std::vec::Drain<'_, T, A>
  13. Implemented via impl<T: SimdElement, const N: usize> AsRef<[T]> for Simd<T, N> where LaneCount<N>: SupportedLaneCount