- Notifications
You must be signed in to change notification settings - Fork0
Byte-order-aware numeric types.
License
Apache-2.0, MIT licenses found
Licenses found
rust-osdev/endian-num
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This crate provides theBe
(big-endian) andLe
(little-endian) byte-order-aware numeric types.
Unlike the popularbyteorder
crate, which focuses on the action of encoding and decoding numbers to and from byte streams, this crate focuses on the state of numbers.This is useful to create structs that contain fields of a specific endianness for interoperability, such as in virtio.In comparison to other crates that focus on state, this crate closely follows naming conventions fromcore::num
, has rich functionality, and extensive documentation of each method.
The core API looksroughly like this (correspondingly forBe
):
#[repr(transparent)]pubstruct<T>Le(pubT);implLe<T:Integer>{pubconstfnfrom_ne(n:T) ->Self;pubconstfnfrom_be(n:Be<T>) ->Self;pubconstfnto_ne(self) ->T;pubconstfnto_be(self) ->Be<T>;pubconstfnto_be_bytes(self) ->[u8; mem::size_of::<Self>()];pubconstfnto_le_bytes(self) ->[u8; mem::size_of::<Self>()];pubconstfnto_ne_bytes(self) ->[u8; mem::size_of::<Self>()];pubconstfnfrom_be_bytes(bytes:[u8; mem::size_of::<Self>()]) ->Self;pubconstfnfrom_le_bytes(bytes:[u8; mem::size_of::<Self>()]) ->Self;pubconstfnfrom_ne_bytes(bytes:[u8; mem::size_of::<Self>()]) ->Self;}
The types also implement appropriate traits fromcore::cmp
,core::convert
,core::fmt
, andcore::ops
and provide additional helper methods for computations.
For API documentation, see thedocs.
Licensed under either of
- Apache License, Version 2.0(LICENSE-APACHE orhttp://www.apache.org/licenses/LICENSE-2.0)
- MIT license(LICENSE-MIT orhttp://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shall bedual licensed as above, without any additional terms or conditions.
About
Byte-order-aware numeric types.
Topics
Resources
License
Apache-2.0, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.