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]
impl<'a, T: Endian> Endian for &'a mut [T]
Traverse a slice, performing the Endian
method on each item in place.
impl Endian for bool
[src]
impl Endian for bool
Implement on bool
.
bool
is always one byte, and single bytes don`t have endian order.
impl Endian for char
[src]
impl Endian for char
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]
fn from_be(self) -> Self
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]
fn from_le(self) -> Self
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]
fn to_be(self) -> Self
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]
fn to_le(self) -> Self
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.
impl Endian for i8
[src]
impl Endian for i8
impl Endian for u8
[src]
impl Endian for u8
impl Endian for i16
[src]
impl Endian for i16
impl Endian for u16
[src]
impl Endian for u16
impl Endian for i32
[src]
impl Endian for i32
impl Endian for u32
[src]
impl Endian for u32
impl Endian for i64
[src]
impl Endian for i64
impl Endian for u64
[src]
impl Endian for u64
impl Endian for i128
[src]
impl Endian for i128
impl Endian for u128
[src]
impl Endian for u128
impl Endian for f32
[src]
impl Endian for f32
impl Endian for f64
[src]
impl Endian for f64