Trait bytepack::Packed
[−]
[src]
pub trait Packed { fn switch_endianness(&mut self); }
This trait both identifies a type which holds his data packed together in memory and a type
which offers a switch_endianness
method. This trait is voluntarily not implemented for
isize
and usize
because their size can vary from one system to another.
Example
If you would like to read and write one of your struct using bytepack
, you can implement
Packed
for it:
use bytepack::Packed; struct Foo { a: i16, b: f32, c: u8 } impl Packed for Foo { fn switch_endianness(&mut self) { self.a.switch_endianness(); self.b.switch_endianness(); self.c.switch_endianness(); } }
However you need to make sure your struct is indeed "packed" and that reading and writing it as one continuous memory zone makes sense. For example the following structures are not "packed" because they all hold a reference to their data.
struct NotPacked1 { name: String } struct NotPacked2 { numbers: Vec<f32> } struct NotPacked3 { count: Rc<u64> }
Required Methods
fn switch_endianness(&mut self)
Perform an in-place switch of the endianness. This might be a no-op in some cases.
Implementors
impl Packed for bool
impl Packed for u8
impl Packed for i8
impl Packed for u16
impl Packed for i16
impl Packed for u32
impl Packed for i32
impl Packed for u64
impl Packed for i64
impl Packed for f32
impl Packed for f64
impl<T> Packed for [T; 1] where T: Packed
impl<T> Packed for [T; 2] where T: Packed
impl<T> Packed for [T; 3] where T: Packed
impl<T> Packed for [T; 4] where T: Packed
impl<T> Packed for [T; 5] where T: Packed