Skip to content

Tracking Issue for ByteStr/ByteString #134915

Open

Description

@joshtriplett

View all comments

Feature gate: #![feature(bstr)]

This is a tracking issue for the ByteStr/ByteString types, which represent human-readable strings that are usually, but not always, UTF-8. Unlike &str/String, these types permit non-UTF-8 contents, making them suitable for user input, non-native filenames (as Path only supports native filenames), and other applications that need to round-trip whatever data the user provides.

This was approved in ACP rust-lang/libs-team#502 .

Public API

// In core::bstr
#[repr(transparent)]
pub struct ByteStr(pub [u8]);

impl ByteStr {
    pub fn new<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &Self { ... }
}

impl Debug for ByteStr { ... }
impl Display for ByteStr { ... }
impl Deref for ByteStr { type Target = [u8]; ... }
impl DerefMut for ByteStr { ... }
// Other trait impls from bstr, including From impls

// In alloc::bstr
#[repr(transparent)]
pub struct ByteString(pub Vec<u8>);

impl Debug for ByteString { ... }
impl Display for ByteString { ... }
impl Deref for ByteString { type Target = Vec<u8>; ... }
impl DerefMut for ByteString { ... }
// Other trait impls from bstr, including From impls

Steps / History

Unresolved Questions

  • Should we call this BStr/BString, or ByteStr/ByteString? The former will be more familiar to users of the bstr crate in the ecosystem. The latter is more explicit, and avoids potential naming conflicts (making it easier to, for instance, add it to the prelude).
  • Should the module be called bstr or change to something like byte_str? Tracking Issue for ByteStr/ByteString #134915 (comment)
  • Should the Display impl use the Unicode replacement character, or do escaping like the Debug impl?
  • Add indexing for the new std::range types, or switch to it exclusively

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Dec 30, 2024
  2. changed the title [-]Tracking Issue for BStr/BString[/-] [+]Tracking Issue for ByteStr/ByteString[/+] on Dec 30, 2024
  3. joshtriplett commented on Jan 3, 2025

    @joshtriplett
    MemberAuthor

    In the course of implementing this, I'm addressing BurntSushi/bstr#190 : both the ByteStr and ByteString types will implement Index and IndexMut.

  4. added 2 commits that reference this issue on Jan 6, 2025
  5. 124 remaining items

  6. added 2 commits that reference this issue on Jul 27, 2026
  7. added a commit that references this issue on Jul 27, 2026
  8. DanielEScherzer commented on Aug 11, 2026

    @DanielEScherzer
    Contributor

    Should the Display impl use the Unicode replacement character, or do escaping like the Debug impl?

    In #159300 the display impl was moved to a separate feature gate (bstr_to_string) so hopefully this doesn't block stabilization of the overall type

  9. clarfonthey commented on Aug 11, 2026

    @clarfonthey
    Contributor

    (FWIW, trait implementations can't be unstable, so, we're still going to need to discuss Display on stabilisation. But the methods at least are unstable, and we can comment out the Display impl if we need.)

    In terms of final changes before stabilisation, I opened #160912 to rename the module to byte_str from bstr, which we haven't fully discussed but I assumed we wanted. If the type is going to be named ByteStr instead of BStr, we will want this.

    I'll rebase the opaque rewrite on top of that one, but I figured the module/feature rename would be easier to do first.

  10. programmerjake commented on Aug 11, 2026

    @programmerjake
    Member
  11. clarfonthey commented on Aug 11, 2026

    @clarfonthey
    Contributor

    That also goes into the entire separate issue that I've been meaning to write up, which is that rustc-dev-guide and std-dev-guide do not have the same information and should probably be merged somehow.

  12. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  13. clarfonthey commented on Nov 4, 2026

    @clarfonthey
    Contributor

    Would someone on the FCP list be willing to cancel FCP here? Since we probably would want to redo FCP on the stabilization PR when it happens.

  14. ChrisDenton commented on Nov 4, 2026

    @ChrisDenton
    Member

    @rfcbot canceled

  15. rust-rfcbot commented on Nov 4, 2026

    @rust-rfcbot
    Collaborator

    @ChrisDenton proposal cancelled.

  16. removed
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions