Now supporting primitive type conversion with a trait!

This changes the old Transmutable trait to Converter and adds a new
Transmutable trait to all the primitive number types.
This commit is contained in:
Jason Travis Smith
2016-01-05 17:46:31 -05:00
parent 010abeff7c
commit e7f2f252fa
4 changed files with 621 additions and 258 deletions

View File

@ -1,7 +1,8 @@
use std::mem;
use std::ptr::copy_nonoverlapping;
use super::transmutable::Transmutable;
use ::converter::Converter;
/// Handles serialization where the most
@ -27,6 +28,23 @@ pub type PlatformEndian = BigEndian;
#[cfg(not(target_endian="big"))]
pub type PlatformEndian = LittleEndian;
/// Create an enumeration of the different
/// available endianesses.
pub enum Endianess
{
/// Referes to BigEndian.
BIG,
/// Referes to LittleEndian.
LITTLE,
/// Referes to PlatformEndian. This can be anyone
/// of the other available endians depending on
/// the platform you are on.
PLATFORM
}
/// Handles reading bytes from a given buffer
/// and turning them into the requested type.
@ -75,7 +93,7 @@ macro_rules! write_bytes
impl Transmutable for BigEndian
impl Converter for BigEndian
{
fn bytes_to_u16(buffer: &[u8]) -> u16
{
@ -147,7 +165,7 @@ impl Transmutable for BigEndian
}
}
impl Transmutable for LittleEndian
impl Converter for LittleEndian
{
fn bytes_to_u16(buffer: &[u8]) -> u16
{