Skip to content

consider including byte literals (alternative to integer literals for [u8] and u8) #4334

Closed
@thestinger

Description

@thestinger

It would be nice if b"foo" could be used instead of str::as_bytes_slice("foo"), and especially ~b"bar" instead of vec::from_slice(str::as_bytes_slice("bar")). Python uses this convention and only allows ASCII inside the byte string literals (along with byte escape codes). I don't really think it's necessary to forbid Unicode though - Python does that to make a very clear distinction between bytes and strings.

There could also be a byte version of a char literal, allowing any ASCII character (b'\n') - a 55u8 literal removes the need for escape codes there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-UnicodeArea: UnicodeA-frontendArea: Compiler frontend (errors, parsing and HIR)C-enhancementCategory: An issue proposing an enhancement or a PR with one.P-lowLow priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions