From 6a9e75a05c50b0e970685a291ea5ca7b7a184d98 Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Thu, 23 Nov 2017 00:02:24 -0500 Subject: [PATCH] Added Sized to aid in less typing so the trait can define common funcs. Changed the use of Vectors to the Spellbook DynamicArray class. --- Cargo.toml | 3 + src/converter.rs | 24 +-- src/endian.rs | 30 +-- src/lib.rs | 3 +- src/macros.rs | 12 +- src/transmutable.rs | 450 ++++++-------------------------------------- 6 files changed, 102 insertions(+), 420 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a212c66..603b60b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,9 @@ convert_sigils = ["sigils"] [dependencies.scribe] git = "ssh://git@gitlab.com/CyberMages/Core/scribe.git" +[dependencies.spellbook] +git = "ssh://git@gitlab.com/CyberMages/Core/spellbook.git" + [dependencies.sigils] git = "ssh://git@gitlab.com/CyberMages/Core/sigils.git" optional = true diff --git a/src/converter.rs b/src/converter.rs index a34a986..9e37110 100644 --- a/src/converter.rs +++ b/src/converter.rs @@ -1,5 +1,7 @@ use std::mem; +use spellbook::components::DynamicArray; + use ::byte_sized::ByteSized; @@ -89,7 +91,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn i16_to_bytes(num: i16) -> Vec + fn i16_to_bytes(num: i16) -> DynamicArray { Self::u16_to_bytes(num as u16) } @@ -100,7 +102,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn i32_to_bytes(num: i32) -> Vec + fn i32_to_bytes(num: i32) -> DynamicArray { Self::u32_to_bytes(num as u32) } @@ -111,7 +113,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn i64_to_bytes(num: i64) -> Vec + fn i64_to_bytes(num: i64) -> DynamicArray { Self::u64_to_bytes(num as u64) } @@ -126,7 +128,7 @@ pub trait Converter /// This will panic if the number of bytes /// passed in is less than the byte size of the given number /// or more than eight. - fn isize_to_bytes(num: isize) -> Vec + fn isize_to_bytes(num: isize) -> DynamicArray { let temp_num: usize; @@ -140,7 +142,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn f32_to_bytes(num: f32) -> Vec + fn f32_to_bytes(num: f32) -> DynamicArray { unsafe { @@ -154,7 +156,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn f64_to_bytes(num: f64) -> Vec + fn f64_to_bytes(num: f64) -> DynamicArray { unsafe { @@ -202,7 +204,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn u16_to_bytes(num: u16) -> Vec; + fn u16_to_bytes(num: u16) -> DynamicArray; /// Converts an unsigned 32-bit integer to bytes /// and places them into the given buffer. @@ -210,7 +212,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn u32_to_bytes(num: u32) -> Vec; + fn u32_to_bytes(num: u32) -> DynamicArray; /// Converts an unsigned 64-bit integer to bytes /// and places them into the given buffer. @@ -218,7 +220,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough space to store the converted value. - fn u64_to_bytes(num: u64) -> Vec; + fn u64_to_bytes(num: u64) -> DynamicArray; /// Converts an unsigned integer to bytes /// and places them into the given buffer. @@ -230,7 +232,7 @@ pub trait Converter /// This will panic if the number of bytes /// passed in is less than the byte size of the given number /// or more than eight. - fn usize_to_bytes(num: usize) -> Vec; + fn usize_to_bytes(num: usize) -> DynamicArray; /// Converts a String to bytes @@ -250,7 +252,7 @@ pub trait Converter /// # Panics /// This will panic if the buffer does not have /// enough information to convert. - fn string_to_bytes(string: String) -> Vec; + fn string_to_bytes(string: String) -> DynamicArray; } diff --git a/src/endian.rs b/src/endian.rs index 2dd2618..9be8f1c 100644 --- a/src/endian.rs +++ b/src/endian.rs @@ -1,3 +1,5 @@ +use spellbook::components::DynamicArray; + use ::byte_sized::ByteSized; use ::byte_sized::U64_BYTES; use ::converter::Converter; @@ -144,25 +146,25 @@ impl Converter for BigEndian } - fn u16_to_bytes(num: u16) -> Vec + fn u16_to_bytes(num: u16) -> DynamicArray { // Unpack the value into it's byte form. unpack_big_endian!(num, u16::BYTES) } - fn u32_to_bytes(num: u32) -> Vec + fn u32_to_bytes(num: u32) -> DynamicArray { // Unpack the value into it's byte form. unpack_big_endian!(num, u32::BYTES) } - fn u64_to_bytes(num: u64) -> Vec + fn u64_to_bytes(num: u64) -> DynamicArray { // Unpack the value into it's byte form. unpack_big_endian!(num, u64::BYTES) } - fn usize_to_bytes(num: usize) -> Vec + fn usize_to_bytes(num: usize) -> DynamicArray { // Unpack the value into it's byte form. unpack_big_endian!(num, usize::BYTES) @@ -204,11 +206,11 @@ impl Converter for BigEndian new_string } - fn string_to_bytes(string: String) -> Vec + fn string_to_bytes(string: String) -> DynamicArray { let bytes: &[u8]; let byte_count: u64; - let mut buffer: Vec; + let mut buffer: DynamicArray; // Turn the string into a byte array. bytes = string.as_bytes(); @@ -218,7 +220,7 @@ impl Converter for BigEndian byte_count = bytes.len() as u64; // Make sure the buffer has enough space for this string. - buffer = Vec::with_capacity(bytes.len() + U64_BYTES); + buffer = DynamicArray::with_capacity(bytes.len() + U64_BYTES); // Add the count to the buffer. buffer.append(&mut BigEndian::u64_to_bytes(byte_count)); @@ -272,25 +274,25 @@ impl Converter for LittleEndian } - fn u16_to_bytes(num: u16) -> Vec + fn u16_to_bytes(num: u16) -> DynamicArray { // Unpack the value into it's byte form. unpack_little_endian!(num, u16::BYTES) } - fn u32_to_bytes(num: u32) -> Vec + fn u32_to_bytes(num: u32) -> DynamicArray { // Unpack the value into it's byte form. unpack_little_endian!(num, u32::BYTES) } - fn u64_to_bytes(num: u64) -> Vec + fn u64_to_bytes(num: u64) -> DynamicArray { // Unpack the value into it's byte form. unpack_little_endian!(num, u64::BYTES) } - fn usize_to_bytes(num: usize) -> Vec + fn usize_to_bytes(num: usize) -> DynamicArray { // Unpack the value into it's byte form. unpack_little_endian!(num, usize::BYTES) @@ -332,11 +334,11 @@ impl Converter for LittleEndian new_string } - fn string_to_bytes(string: String) -> Vec + fn string_to_bytes(string: String) -> DynamicArray { let bytes: &[u8]; let byte_count: u64; - let mut buffer: Vec; + let mut buffer: DynamicArray; // Turn the string into a byte array. bytes = string.as_bytes(); @@ -346,7 +348,7 @@ impl Converter for LittleEndian byte_count = bytes.len() as u64; // Make sure the buffer has enough space for this string. - buffer = Vec::with_capacity(bytes.len() + U64_BYTES); + buffer = DynamicArray::with_capacity(bytes.len() + U64_BYTES); // Add the count to the buffer. buffer.append(&mut LittleEndian::u64_to_bytes(byte_count)); diff --git a/src/lib.rs b/src/lib.rs index 3749638..69bdcac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,6 @@ #![doc(html_logo_url="", html_favicon_url="http://cybermagesllc.com/favicon.ico", html_root_url="http://cybermagesllc.com")] -#![feature(associated_consts)] #![warn(missing_docs)] @@ -15,6 +14,8 @@ extern crate scribe; #[cfg(feature="sigils")] extern crate sigils; +extern crate spellbook; + #[macro_use] diff --git a/src/macros.rs b/src/macros.rs index 2eb66ed..30e3071 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -63,11 +63,11 @@ macro_rules! unpack_big_endian ($value: expr, $bytes: expr) => { { - let mut buffer: Vec; + let mut buffer: ::spellbook::components::DynamicArray; // Create an array with enough space for this value // and then bit shift the value into a buffer of bytes. - buffer = Vec::with_capacity($bytes); + buffer = ::spellbook::components::DynamicArray::with_capacity($bytes); for i in 0..$bytes { buffer.push(($value >> (($bytes - i) - 1) * 8) as u8); @@ -85,11 +85,11 @@ macro_rules! unpack_little_endian ($value: expr, $bytes: expr) => { { - let mut buffer: Vec; + let mut buffer: ::spellbook::components::DynamicArray; // Create an array with enough space for this value // and then bit shift the value into a buffer of bytes. - buffer = Vec::with_capacity($bytes); + buffer = ::spellbook::components::DynamicArray::with_capacity($bytes); for i in 0..$bytes { buffer.push(($value >> (i * 8)) as u8); @@ -107,7 +107,7 @@ macro_rules! swap_big_to_little_endian ($value: expr, $target_type: ty, $bytes: expr) => { { - let buffer: Vec; + let buffer: ::spellbook::components::DynamicArray; // Convert the big endian value to bytes. buffer = unpack_big_endian!($value, $bytes); @@ -124,7 +124,7 @@ macro_rules! swap_little_to_big_endian ($value: expr, $target_type: ty, $bytes: expr) => { { - let buffer: Vec; + let buffer: ::spellbook::components::DynamicArray; // Convert the little endian value to bytes. buffer = unpack_little_endian!($value, $bytes); diff --git a/src/transmutable.rs b/src/transmutable.rs index aa71ee2..1cf5bb7 100644 --- a/src/transmutable.rs +++ b/src/transmutable.rs @@ -1,8 +1,10 @@ +use spellbook::components::DynamicArray; + #[cfg(feature="convert_sigils")] use sigils::{Zero, Number, Real}; #[cfg(feature="convert_sigils")] -use sigils::vector::{Vector, Vector2, Vector3, Vector4}; +use sigils::vector::{DynamicArraytor, DynamicArraytor2, DynamicArraytor3, DynamicArraytor4}; #[cfg(feature="convert_sigils")] use sigils::quaternion::Quaternion; @@ -17,11 +19,14 @@ use ::endian::Endianess; // From and Into are not used because we need to also // know the endianess to use for converting. /// A type that can be converted to and from bytes. -pub trait Transmutable +pub trait Transmutable: Sized { /// Transmute an array of bytes in the /// platform's endian to this type. - fn from_bytes(buffer: &[u8]) -> Self; + fn from_bytes(buffer: &[u8]) -> Self + { + Self::from_endian_bytes(buffer, Endianess::Platform) + } /// Transmute an array of bytes in the /// given endian to this type. @@ -30,20 +35,29 @@ pub trait Transmutable /// Transmute this type to an array of bytes in /// the Platform's endian. - fn to_bytes(self) -> Vec; + fn to_bytes(self) -> DynamicArray + { + 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) -> Vec; + fn to_endian_bytes(self, endianess: Endianess) -> DynamicArray + { + self.as_endian_bytes(endianess) + } /// Transmute this type to an array of bytes in /// the Platform's endian. - fn as_bytes(&self) -> Vec; + fn as_bytes(&self) -> DynamicArray + { + self.as_endian_bytes(Endianess::Platform) + } /// Transmute this type to an array of bytes in /// the desired endian. - fn as_endian_bytes(&self, endianess: Endianess) -> Vec; + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray; /// Get the current size of this Transmutable in bytes. @@ -122,11 +136,6 @@ macro_rules! handle_endianess_from_bytes impl Transmutable for u8 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - #[allow(unused_variables)] fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { @@ -139,23 +148,8 @@ impl Transmutable for u8 buffer[0] } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - #[allow(unused_variables)] - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // A single byte has no endian form. vec![*self] @@ -169,11 +163,6 @@ impl Transmutable for u8 impl Transmutable for u16 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -184,22 +173,7 @@ impl Transmutable for u16 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u16) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Return the Endianess conversion. handle_endianess_to_bytes!(self, endianess, u16_to_bytes) @@ -213,11 +187,6 @@ impl Transmutable for u16 impl Transmutable for u32 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -228,22 +197,7 @@ impl Transmutable for u32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u32) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, u32_to_bytes) @@ -257,11 +211,6 @@ impl Transmutable for u32 impl Transmutable for u64 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -272,22 +221,7 @@ impl Transmutable for u64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u64) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, u64_to_bytes) @@ -301,11 +235,6 @@ impl Transmutable for u64 impl Transmutable for usize { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -316,22 +245,7 @@ impl Transmutable for usize handle_endianess_from_bytes!(buffer, endianess, bytes_to_usize) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, usize_to_bytes) @@ -345,11 +259,6 @@ impl Transmutable for usize impl Transmutable for i8 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - #[allow(unused_variables)] fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { @@ -360,23 +269,8 @@ impl Transmutable for i8 buffer[0] as i8 } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - #[allow(unused_variables)] - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { vec![*self as u8] } @@ -389,11 +283,6 @@ impl Transmutable for i8 impl Transmutable for i16 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -404,22 +293,7 @@ impl Transmutable for i16 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i16) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, i16_to_bytes) @@ -433,11 +307,6 @@ impl Transmutable for i16 impl Transmutable for i32 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -448,22 +317,7 @@ impl Transmutable for i32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i32) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, i32_to_bytes) @@ -477,11 +331,6 @@ impl Transmutable for i32 impl Transmutable for i64 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -492,22 +341,7 @@ impl Transmutable for i64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i64) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, i64_to_bytes) @@ -521,11 +355,6 @@ impl Transmutable for i64 impl Transmutable for isize { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -536,22 +365,7 @@ impl Transmutable for isize handle_endianess_from_bytes!(buffer, endianess, bytes_to_isize) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, isize_to_bytes) @@ -565,11 +379,6 @@ impl Transmutable for isize impl Transmutable for f32 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -580,22 +389,7 @@ impl Transmutable for f32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f32) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, f32_to_bytes) @@ -609,11 +403,6 @@ impl Transmutable for f32 impl Transmutable for f64 { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Make sure that there is enough data to read @@ -624,22 +413,7 @@ impl Transmutable for f64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, f64_to_bytes) @@ -653,33 +427,13 @@ impl Transmutable for f64 impl Transmutable for String { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { // Convert the given bytes to this type and return it. handle_endianess_from_bytes!(buffer, endianess, bytes_to_string) } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { // Convert this to bytes and add it to the buffer. // We are not using the macro because *String is a str. @@ -714,22 +468,17 @@ impl Transmutable for String } #[cfg(feature="convert_sigils")] -impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable +impl Transmutable for DynamicArraytor2 where T: Number + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; let num_bytes: usize; - let mut vec: Vector2; + let mut vec: DynamicArraytor2; // Determine the number of bytes requires to - // represent a Vector2. - vec = Vector2::::zero(); + // represent a DynamicArraytor2. + vec = DynamicArraytor2::::zero(); byte_size = T::get_byte_size(); num_bytes = byte_size * vec.get_size() as usize; @@ -745,35 +494,20 @@ impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable vec } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { let byte_size: usize; let num_bytes: usize; - let mut buffer: Vec; + let mut buffer: DynamicArray; // Determine the number of bytes requires to - // represent a Vector2. + // represent a DynamicArraytor2. byte_size = T::get_byte_size(); num_bytes = byte_size * self.get_size() as usize; // Make sure that there is enough space to store // the bytes from this type. - buffer = Vec::with_capacity(num_bytes); + buffer = DynamicArray::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.x.as_endian_bytes(endianess)); @@ -790,22 +524,17 @@ impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable } #[cfg(feature="convert_sigils")] -impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable +impl Transmutable for DynamicArraytor3 where T: Number + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; let num_bytes: usize; - let mut vec: Vector3; + let mut vec: DynamicArraytor3; // Determine the number of bytes requires to - // represent a Vector3. - vec = Vector3::::zero(); + // represent a DynamicArraytor3. + vec = DynamicArraytor3::::zero(); byte_size = T::get_byte_size(); num_bytes = byte_size * vec.get_size() as usize; @@ -823,35 +552,20 @@ impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable vec } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { let byte_size: usize; let num_bytes: usize; - let mut buffer: Vec; + let mut buffer: DynamicArray; // Determine the number of bytes requires to - // represent a Vector3. + // represent a DynamicArraytor3. byte_size = T::get_byte_size(); num_bytes = byte_size * self.get_size() as usize; // Make sure that there is enough space to store // the bytes from this type. - buffer = Vec::with_capacity(num_bytes); + buffer = DynamicArray::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.x.as_endian_bytes(endianess)); @@ -869,22 +583,17 @@ impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable } #[cfg(feature="convert_sigils")] -impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable +impl Transmutable for DynamicArraytor4 where T: Number + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; let num_bytes: usize; - let mut vec: Vector4; + let mut vec: DynamicArraytor4; // Determine the number of bytes requires to - // represent a Vector4. - vec = Vector4::::zero(); + // represent a DynamicArraytor4. + vec = DynamicArraytor4::::zero(); byte_size = T::get_byte_size(); num_bytes = byte_size * vec.get_size() as usize; @@ -904,35 +613,20 @@ impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable vec } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { let byte_size: usize; let num_bytes: usize; - let mut buffer: Vec; + let mut buffer: DynamicArray; // Determine the number of bytes requires to - // represent a Vector4. + // represent a DynamicArraytor4. byte_size = T::get_byte_size(); num_bytes = byte_size * self.get_size() as usize; // Make sure that there is enough space to store // the bytes from this type. - buffer = Vec::with_capacity(num_bytes); + buffer = DynamicArray::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.x.as_endian_bytes(endianess)); @@ -954,11 +648,6 @@ impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable impl Transmutable for Quaternion where T: Real + ByteSized + Transmutable { - fn from_bytes(buffer: &[u8]) -> Self - { - Self::from_endian_bytes(buffer, Endianess::Platform) - } - fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; @@ -978,31 +667,16 @@ impl Transmutable for Quaternion // Convert the given bytes to this type and return it. quat.scalar = T::from_endian_bytes(&buffer[0..byte_size], endianess); quat.vector = - Vector3::::from_endian_bytes(&buffer[byte_size..num_bytes], + DynamicArraytor3::::from_endian_bytes(&buffer[byte_size..num_bytes], endianess); quat } - fn to_bytes(self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn to_endian_bytes(self, endianess: Endianess) -> Vec - { - self.as_endian_bytes(endianess) - } - - fn as_bytes(&self) -> Vec - { - self.as_endian_bytes(Endianess::Platform) - } - - fn as_endian_bytes(&self, endianess: Endianess) -> Vec + fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray { let byte_size: usize; let num_bytes: usize; - let mut buffer: Vec; + let mut buffer: DynamicArray; // Determine the number of bytes requires to // represent a Quaternion. @@ -1011,7 +685,7 @@ impl Transmutable for Quaternion // Make sure that there is enough space to store // the bytes from this type. - buffer = Vec::with_capacity(num_bytes); + buffer = DynamicArray::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.scalar.as_endian_bytes(endianess));