Skip to content

Remove dependency on byteorder crate, make byteorder type methods const #438

@joshlf

Description

@joshlf

Summary

Remove our dependency on the byteorder crate and remove the byteorder feature, making the byteorder module available unconditinoally.

Progress

In progress in #583.

  • Update #583 to have const fns no longer be const so that it works with our MSRV
  • Support functions which are conditionally const depending on Rust version (as prototyped in #574)
  • Make byteorder functions conditionally const

Description

Some potential users have expressed concerns over our dependency on the byteorder crate. I have not seen any uses of the types in our byteorder module which mix those types with other uses of the byteorder crate, which implies that we could just define our own ByteOrder trait rather than using the one from the byteorder crate and this wouldn't cause problems for users.

While we're at it, we could use a technique like the following to allow the methods on our types to be const fns:

use core::marker::PhantomData;

pub trait ByteOrder {
    #[doc(hidden)]
    const ORDER: Order;
}

#[doc(hidden)]
pub enum Order {
    BigEndian,
    LittleEndian,
}

#[repr(transparent)]
pub struct U64<O>([u8; core::mem::size_of::<u64>()], PhantomData<O>);

impl<O: ByteOrder> U64<O> {
    pub const fn new(u: u64) -> U64<O> {
        let bytes = match O::ORDER {
            Order::BigEndian => u.to_be_bytes(),
            Order::LittleEndian => u.to_le_bytes(),
        };
        
        U64(bytes, PhantomData)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocking-next-releaseThis issue should be resolved before we release on crates.iocompatibility-breakingChanges that are (likely to be) breaking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions