diff --git a/src/lib.rs b/src/lib.rs index 5d38d9c..4bb6f8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,11 +12,12 @@ extern crate scribe; extern crate weave; -extern crate spellbook; #[cfg(feature="sigils")] extern crate sigils; +extern crate spellbook; + #[macro_use] diff --git a/src/transmutable.rs b/src/transmutable.rs index 10ad7a9..d419bc4 100644 --- a/src/transmutable.rs +++ b/src/transmutable.rs @@ -24,7 +24,10 @@ pub trait Transmutable: Sized { /// Transmute an array of bytes in the /// platform's endian to this type. - fn from_bytes(buffer: &[u8]) -> Result; + fn from_bytes(buffer: &[u8]) -> Result + { + Self::from_endian_bytes(buffer, Endianess::Platform) + } /// Transmute an array of bytes in the /// given endian to this type. @@ -34,16 +37,25 @@ pub trait Transmutable: Sized /// Transmute this type to an array of bytes in /// the Platform's endian. - fn to_bytes(self) -> Array; + fn to_bytes(self) -> Array + { + self.as_endian_bytes(Endianess::Platform) + } /// Transmute this type to an array of bytes in /// the desired endian. - fn to_endian_bytes(self, endianess: Endianess) -> Array; + fn to_endian_bytes(self, endianess: Endianess) -> Array + { + self.as_endian_bytes(endianess) + } /// Transmute this type to an array of bytes in /// the Platform's endian. - fn as_bytes(&self) -> Array; + fn as_bytes(&self) -> Array + { + self.as_endian_bytes(Endianess::Platform) + } /// Transmute this type to an array of bytes in /// the desired endian. @@ -126,11 +138,6 @@ macro_rules! handle_endianess_from_bytes impl Transmutable for u8 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - #[allow(unused_variables)] fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result @@ -141,21 +148,6 @@ impl Transmutable for u8 Ok(buffer[0]) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - #[allow(unused_variables)] fn as_endian_bytes(&self, endianess: Endianess) -> Array { @@ -171,11 +163,6 @@ impl Transmutable for u8 impl Transmutable for u16 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -183,21 +170,6 @@ impl Transmutable for u16 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u16) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Return the Endianess conversion. @@ -212,11 +184,6 @@ impl Transmutable for u16 impl Transmutable for u32 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -224,21 +191,6 @@ impl Transmutable for u32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u32) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -253,11 +205,6 @@ impl Transmutable for u32 impl Transmutable for u64 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -265,21 +212,6 @@ impl Transmutable for u64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u64) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -294,11 +226,6 @@ impl Transmutable for u64 impl Transmutable for usize { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -306,21 +233,6 @@ impl Transmutable for usize handle_endianess_from_bytes!(buffer, endianess, bytes_to_usize) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -335,11 +247,6 @@ impl Transmutable for usize impl Transmutable for i8 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - #[allow(unused_variables)] fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result @@ -349,21 +256,6 @@ impl Transmutable for i8 Ok(buffer[0] as i8) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - #[allow(unused_variables)] fn as_endian_bytes(&self, endianess: Endianess) -> Array { @@ -378,11 +270,6 @@ impl Transmutable for i8 impl Transmutable for i16 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -390,21 +277,6 @@ impl Transmutable for i16 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i16) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -419,11 +291,6 @@ impl Transmutable for i16 impl Transmutable for i32 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -431,21 +298,6 @@ impl Transmutable for i32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i32) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -460,11 +312,6 @@ impl Transmutable for i32 impl Transmutable for i64 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -472,21 +319,6 @@ impl Transmutable for i64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i64) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -501,11 +333,6 @@ impl Transmutable for i64 impl Transmutable for isize { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -513,21 +340,6 @@ impl Transmutable for isize handle_endianess_from_bytes!(buffer, endianess, bytes_to_isize) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -542,11 +354,6 @@ impl Transmutable for isize impl Transmutable for f32 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -554,21 +361,6 @@ impl Transmutable for f32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f32) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -583,11 +375,6 @@ impl Transmutable for f32 impl Transmutable for f64 { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -595,21 +382,6 @@ impl Transmutable for f64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -624,11 +396,6 @@ impl Transmutable for f64 impl Transmutable for String { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -636,21 +403,6 @@ impl Transmutable for String handle_endianess_from_bytes!(buffer, endianess, bytes_to_string) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. @@ -688,11 +440,6 @@ impl Transmutable for String #[cfg(feature="convert_sigils")] impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -716,21 +463,6 @@ impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable Ok(vec) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { let num_bytes: usize; @@ -761,11 +493,6 @@ impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable #[cfg(feature="convert_sigils")] impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -789,21 +516,6 @@ impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable Ok(vec) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { let num_bytes: usize; @@ -835,11 +547,6 @@ impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable #[cfg(feature="convert_sigils")] impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -865,21 +572,6 @@ impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable Ok(vec) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { let num_bytes: usize; @@ -913,11 +605,6 @@ impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable impl Transmutable for Quaternion where T: Real + Trig + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Result - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Result { @@ -942,21 +629,6 @@ impl Transmutable for Quaternion Ok(quat) } - fn to_bytes(self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Array - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Array - { - self.as_endian_bytes(Endianess::Platform) - } - fn as_endian_bytes(&self, endianess: Endianess) -> Array { let num_bytes: usize;