Trait endian_trait::Endian
[−]
[src]
pub trait Endian { fn to_be(self) -> Self; fn to_le(self) -> Self; fn from_be(self) -> Self; fn from_le(self) -> Self; }
Convert a type from one endian order to another.
The standard implementation of this trait is simply to call the methods on
the component members of a data type which are themselves Endian
, until the
call stack bottoms out at one of Rust's primitives.
Required Methods
fn to_be(self) -> Self
Converts from host endian to big-endian order.
On big-endian platforms, this is a no-op and should be compiled out.
fn to_le(self) -> Self
Converts from host endian to little-endian order.
On little-endian platforms, this is a no-op and should be compiled out.
fn from_be(self) -> Self
Converts from big-endian order to host endian.
On big-endian platforms, this is a no-op and should be compiled out.
fn from_le(self) -> Self
Converts from little-endian order to host endian.
On little-endian platforms, this is a no-op and should be compiled out.
Implementations on Foreign Types
impl<'a, T: Endian> Endian for &'a mut [T]
[src]
Traverse a slice, performing the Endian
method on each item in place.
impl Endian for bool
[src]
Implement on bool
.
bool
is always one byte, and single bytes don`t have endian order.
impl Endian for char
[src]
Implement on char
.
char
is four bytes wide. Delegate to u32
's implementation and transmute.
This is safe ONLY IF THE CONVERSION MAKES LOGICAL SENSE
char
is Unicode codepoints, NOT integers, so not all values of u32
are
valid values of char
.
The to_
functions will emit potentially invalid char
values, and this is
to be expected. The from_
functions, however, will panic if they are about
to emit an invalid char
byte value.
fn from_be(self) -> Self
[src]
Attempts to create a local char
from a big-endian value.
This function WILL panic if the local value exceeds the maximum Unicode Scalar Value permissible.
fn from_le(self) -> Self
[src]
Attempts to create a local char
from a little-endian value.
This function WILL panic if the local value exceeds the maximum Unicode Scalar Value permissible.
fn to_be(self) -> Self
[src]
Converts a local char
to big-endian.
This may result in a byte value that is not a valid Unicode Scalar Value
and the result of this transform should be passed into a from_be()
before using it in anything that requires char
semantics.
fn to_le(self) -> Self
[src]
Converts a local char
to little-endian.
This may result in a byte value that is not a valid Unicode Scalar Value
and the result of this transform should be passed into a from_le()
before using it in anything that requires char
semantics.