Skip to content

Tracking issue for integer types conversion to and from byte arrays #52963

Closed
@SimonSapin

Description

@SimonSapin
Contributor

A previous incarnation of this API that went though FCP in #49792, but stabilization was reverted while still in Nightly in favor of this API.

Implemented in #51919, conversions between all integer types and appropriately-sized arrays of u8, using the specified endianness:

impl $Int {
    pub fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {}
    pub fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {}
    pub fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {}
    pub fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {}
    pub fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {}
    pub fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {}
}

ne, le, and be mean native-endian, little-endian, and big-endian respectively. Native-endian means the target platform’s endianness. Those conversions are implemented as literally transmute and nothing else (but safe). The other conversions use swap or do not swap the byte order depending on the target’s endianness.

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Aug 1, 2018
added
B-unstableBlocker: Implemented in the nightly compiler and unstable.
on Aug 7, 2018
SimonSapin

SimonSapin commented on Aug 7, 2018

@SimonSapin
ContributorAuthor

I think this feature is ready for stabilization:

@rfcbot fcp merge

This is very soon after landing in Nightly in its current form, but the same functionality already went through FCP for stabilization in #49792 after a couple months in Nightly. The new API contains methods identical to the previous API (only renamed), plus new methods that implement what was previously documented as a typical usage of the previous API.

So there isn’t really anything new here, I expect this final period to be a formality except for possible last-minute naming bikeshed. (The methods landed with consistent abbreviation, another option that was considered was fully expansion with for example to_native_endian_bytes and from_big_endian_bytes.)

rfcbot

rfcbot commented on Aug 7, 2018

@rfcbot
Collaborator

Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams:

Concerns:

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

added
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 Aug 7, 2018
rfcbot

rfcbot commented on Aug 9, 2018

@rfcbot
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

added
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
and removed
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
on Aug 9, 2018
Kimundi

Kimundi commented on Aug 10, 2018

@Kimundi
Member

@rfcbot concern missing_impls

I just noticed that we are still missing half the implementation for this.

#51919 did just add the changes for signed integers, but not for unsigned.

Compare:

https://doc.rust-lang.org/nightly/std/primitive.u8.html#method.to_bytes
https://doc.rust-lang.org/nightly/std/primitive.i8.html#method.to_ne_bytes

cc @tbu-

added
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
and removed
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on Aug 10, 2018

61 remaining items

Loading
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

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @alexcrichton@kallisti5@shepmaster@SimonSapin@nagisa

        Issue actions

          Tracking issue for integer types conversion to and from byte arrays · Issue #52963 · rust-lang/rust