rust/library/alloc/src
Matthias Krüger 510fc3432e
Rollup merge of #129550 - kornelski:boxasstr, r=joshtriplett,dtolnay
Add str.as_str() for easy Deref to string slices

Working with `Box<str>` is cumbersome, because in places like `iter.filter()` it can end up being `&Box<str>` or even `&&Box<str>`, and such type doesn't always get auto-dereferenced as expected.

Dereferencing such box to `&str` requires ugly syntax like `&**boxed_str` or `&***boxed_str`, with the exact amount of `*`s.

`Box<str>` is [not easily comparable with other string types](https://github.com/rust-lang/rust/pull/129852) via `PartialEq`. `Box<str>` won't work for lookups in types like `HashSet<String>`, because `Borrow<String>` won't take types like `&Box<str>`. OTOH `set.contains(s.as_str())` works nicely regardless of levels of indirection.

`String` has a simple solution for this: the `as_str()` method, and `Box<str>` should too.
2024-09-23 06:45:32 +02:00
..
alloc Reformat use declarations. 2024-07-29 08:26:52 +10:00
boxed Reformat use declarations. 2024-07-29 08:26:52 +10:00
collections Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
ffi Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
raw_vec Polymorphize RawVec 2024-08-09 20:06:26 -04:00
rc Add str.as_str() for easy dereferencing of Box<str> 2024-09-19 16:25:56 +01:00
slice Reformat use declarations. 2024-07-29 08:26:52 +10:00
sync Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
testing Reformat use declarations. 2024-07-29 08:26:52 +10:00
vec Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
alloc.rs read_volatile __rust_no_alloc_shim_is_unstable in alloc_zeroed 2024-09-17 22:26:21 -04:00
borrow.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
boxed.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
fmt.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
lib.miri.rs
lib.rs Add str.as_str() for easy dereferencing of Box<str> 2024-09-19 16:25:56 +01:00
macros.rs Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
raw_vec.rs add FIXME(const-hack) 2024-09-08 23:08:40 +02:00
rc.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
slice.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
str.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
string.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
sync.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
task.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
tests.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00