Skip to content

Commit f6d0bb5

Browse files
committed
Implement ByteStr and ByteString types
Approved ACP: rust-lang/libs-team#502 Tracking issue: rust-lang#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`, `Borrow`, and `From`, when those would be the second implementation for a type (counting the `T` impl), to avoid potential inference failures. These impls are important, but we can attempt to add them 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).
1 parent 7349f6b commit f6d0bb5

File tree

9 files changed

+1332
-2
lines changed

9 files changed

+1332
-2
lines changed

Diff for: library/alloc/src/bstr.rs

+690
Large diffs are not rendered by default.

Diff for: library/alloc/src/collections/btree/set/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ fn test_recovery() {
533533

534534
impl PartialOrd for Foo {
535535
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
536-
self.0.partial_cmp(&other.0)
536+
PartialOrd::partial_cmp(&self.0, &other.0)
537537
}
538538
}
539539

Diff for: library/alloc/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
#![feature(async_fn_traits)]
104104
#![feature(async_iterator)]
105105
#![feature(box_uninit_write)]
106+
#![feature(bstr)]
107+
#![feature(bstr_internals)]
106108
#![feature(clone_to_uninit)]
107109
#![feature(coerce_unsized)]
108110
#![feature(const_eval_select)]
@@ -226,6 +228,8 @@ mod boxed {
226228
pub use std::boxed::Box;
227229
}
228230
pub mod borrow;
231+
#[unstable(feature = "bstr", issue = "134915")]
232+
pub mod bstr;
229233
pub mod collections;
230234
#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
231235
pub mod ffi;

0 commit comments

Comments
 (0)