serial_traits 1.1.2

A trait that allows you to serialize to and parse from Vec<u8> buffers. Comes with implementations for primitive types, String and generic collection types (if the item type implements the trait too.)
Documentation
pub mod leb128;
pub mod primitives;
pub mod std;

#[macro_export]
macro_rules! unwrap_return {
    ($data:expr) => {
        match $data {
            Some(value) => value,
            None => return None,
        }
    };
}

pub trait Serializable {
    fn serialize(&self) -> Vec<u8>;
    fn parse(data: &mut Vec<u8>) -> Option<Self>
    where
        Self: Sized;
}

fn get_vec<T: Serializable>(item_count: usize, data: &mut Vec<u8>) -> Option<Vec<T>> {
    let mut result = vec![];

    for _ in 0..item_count {
        result.push(unwrap_return!(T::parse(data)));
    }

    Some(result)
}

fn bin_slice<T: Serializable>(items: &[T]) -> Vec<u8> {
    let mut stuffs = vec![];

    for item in items {
        stuffs.push(item.serialize());
    }

    stuffs.concat()
}

// the `tests/` folder does not work because "Serializable"
// cannot be accessed for some reason no matter what i try.
mod test_leb128;
mod test_primitives;
mod test_std;