Skip to content

Commit

Permalink
Rollup merge of #135073 - joshtriplett:bstr, r=BurntSushi
Browse files Browse the repository at this point in the history
Implement `ByteStr` and `ByteString` types

Approved ACP: rust-lang/libs-team#502
Tracking issue: #134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`,
when those would be the second implementation for a type (counting the
`T` impl), to avoid potential inference failures. We can attempt to add
more impls later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (`@BurntSushi).`

r? `@BurntSushi`
  • Loading branch information
matthiaskrgr authored Jan 23, 2025
2 parents 99768c8 + 865471f commit 08d5b23
Show file tree
Hide file tree
Showing 13 changed files with 1,412 additions and 14 deletions.
702 changes: 702 additions & 0 deletions library/alloc/src/bstr.rs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
#![feature(async_fn_traits)]
#![feature(async_iterator)]
#![feature(box_uninit_write)]
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(clone_to_uninit)]
#![feature(coerce_unsized)]
#![feature(const_eval_select)]
Expand Down Expand Up @@ -228,6 +230,8 @@ mod boxed {
pub use std::boxed::Box;
}
pub mod borrow;
#[unstable(feature = "bstr", issue = "134915")]
pub mod bstr;
pub mod collections;
#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
pub mod ffi;
Expand Down
Loading

0 comments on commit 08d5b23

Please sign in to comment.