1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
mod bytes;
mod impls;
pub mod specialization;
#[cfg(test)]
mod tests;
mod to_raw_bytes;
mod to_sized_array;
mod utils;

pub use bytes::*;
pub use impls::*;
pub use specialization::*;
use std::cmp::Ordering;
use std::fmt;
use std::fmt::{Debug, Display};
use std::hash::{Hash, Hasher};
use std::mem::transmute;
use std::ops::*;
#[cfg(feature = "to_bytes_derive")]
pub use to_bytes_derive::*;

pub mod not_important {
    pub use crate::to_raw_bytes::*;
    pub use crate::to_sized_array::*;
    pub use crate::utils::*;
}
pub use not_important::*;

//\////////////////////////////////////////////////////////////////////////////////////////////////////

pub trait ToBytes {
    fn to_bytes(self) -> Bytes;
}

//\////////////////////////////////////////////////////////////////////////////////////////////////////

pub trait ReadBack<'a>: ToBytes {
    unsafe fn read_back(ptr: *const u8) -> &'a Self;
}
pub trait ReadBackMut<'a>: ToBytes {
    unsafe fn read_back_mut(ptr: *mut u8) -> &'a mut Self;
}
pub trait TransmuteBack: ToBytes {
    unsafe fn transmute_back(ptr: *const u8) -> Self;
}

//\////////////////////////////////////////////////////////////////////////////////////////////////////

#[macro_export]
macro_rules! bytes {
    { } => { Bytes::new() };
    { $e:expr } => { $crate::ToBytes::to_bytes($e) };
    { $($e:expr)* } => {{
        #[allow(unused_mut)]
        let mut b = Bytes::new();
        $(b.append($crate::ToBytes::to_bytes($e));)*
        b
    }};
}