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:
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user