Skip to content

[byteorder] Add submodules with byte order aliases#101

Merged
joshlf merged 1 commit intomainfrom
byteorder-modules
Oct 25, 2022
Merged

[byteorder] Add submodules with byte order aliases#101
joshlf merged 1 commit intomainfrom
byteorder-modules

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Oct 25, 2022

Add submodules which define type aliases for the byteorder::* types with a specific byte order type argument. This allows us to go from the somewhat clunky:

  use byteorder::NetworkEndian;
  use zerocopy::byteorder::U16;

  #[derive(FromBytes, AsBytes, Unaligned)]
  #[repr(C)]
  struct UdpHeader {
      src_port: U16<NetworkEndian>,
      dst_port: U16<NetworkEndian>,
      length: U16<NetworkEndian>,
      checksum: U16<NetworkEndian>,
  }

...to the less clunky:

  use zerocopy::byteorder::network_endian::U16;

  #[derive(FromBytes, AsBytes, Unaligned)]
  #[repr(C)]
  struct UdpHeader {
      src_port: U16,
      dst_port: U16,
      length: U16,
      checksum: U16,
  }

Closes #100

Add submodules which define type aliases for the `byteorder::*` types
with a specific byte order type argument. This allows us to go from the
somewhat clunky:

  use byteorder::NetworkEndian;
  use zerocopy::byteorder::U16;

  #[derive(FromBytes, AsBytes, Unaligned)]
  #[repr(C)]
  struct UdpHeader {
      src_port: U16<NetworkEndian>,
      dst_port: U16<NetworkEndian>,
      length: U16<NetworkEndian>,
      checksum: U16<NetworkEndian>,
  }

...to the less clunky:

  use zerocopy::byteorder::network_endian::U16;

  #[derive(FromBytes, AsBytes, Unaligned)]
  #[repr(C)]
  struct UdpHeader {
      src_port: U16,
      dst_port: U16,
      length: U16,
      checksum: U16,
  }

Closes #100
@joshlf joshlf merged commit 9e5275c into main Oct 25, 2022
@joshlf joshlf deleted the byteorder-modules branch October 25, 2022 22:22
joshlf added a commit that referenced this pull request Aug 3, 2023
Add submodules which define type aliases for the `byteorder::*` types
with a specific byte order type argument. This allows us to go from the
somewhat clunky:

  use byteorder::NetworkEndian;
  use zerocopy::byteorder::U16;

  #[derive(FromBytes, AsBytes, Unaligned)]
  #[repr(C)]
  struct UdpHeader {
      src_port: U16<NetworkEndian>,
      dst_port: U16<NetworkEndian>,
      length: U16<NetworkEndian>,
      checksum: U16<NetworkEndian>,
  }

...to the less clunky:

  use zerocopy::byteorder::network_endian::U16;

  #[derive(FromBytes, AsBytes, Unaligned)]
  #[repr(C)]
  struct UdpHeader {
      src_port: U16,
      dst_port: U16,
      length: U16,
      checksum: U16,
  }

Closes #100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add zerocopy::byteorder::NE typealias for zerocopy::byteorder::NativeEndian

1 participant