lib-endian
This crate is the simplest library for storing a value while handling byte order or for obtaining the byte order of the current target.
Examples
- Get the
Endian
of current target byEndian::NATIVE
.
use Endian;
const NE: Endian = NATIVE;
- Get a native
Endian
or a reversed one byEndian::native_or_reversed(bool)
.
use Endian;
const REVERSE: bool = true;
const NE_REV: Endian = native_or_reversed;
assert_eq!;
const NE: Endian = native_or_reversed;
assert_eq!;
- Reverse a
Endian
by.reverse()
or!
:
use Endian;
const BE: Endian = Little.reverse;
let le = ! Big;
assert_eq!;
- Compare two
Endian
by.is(...)
,==
or!=
:
use Endian;
const BE: Endian = Big;
const EQ: bool = BE.is;
const NEQ: bool = ! Little.is;
let eq = Big == BE;
let neq = BE != Little;
assert!;
Attention
You Can't Use !
, ==
or !=
in
Constant Expressions
because they are implemented by traits,
which, at least in Rust version 1.78.0
, do not contain const fn
.
So in
Constant Expressions,
use v.reverse()
to replace !v
,
a.is(b)
to replace a==b
,
!a.is(b)
to replace a!=b
.