From 5aa603e246c2b2423378c35f351f4511f36c027f Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Tue, 28 Nov 2017 18:47:35 -0500 Subject: [PATCH] Changing to match the Spellbook DynamicArray to Array naming switch. --- src/converter.rs | 24 ++++++------ src/endian.rs | 30 +++++++-------- src/macros.rs | 12 +++--- src/transmutable.rs | 94 ++++++++++++++++++++++----------------------- 4 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/converter.rs b/src/converter.rs index 9e37110..524bad7 100644 --- a/src/converter.rs +++ b/src/converter.rs @@ -1,6 +1,6 @@ use std::mem; -use spellbook::components::DynamicArray; +use spellbook::components::Array; use ::byte_sized::ByteSized; @@ -91,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) -> DynamicArray + fn i16_to_bytes(num: i16) -> Array { Self::u16_to_bytes(num as u16) } @@ -102,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) -> DynamicArray + fn i32_to_bytes(num: i32) -> Array { Self::u32_to_bytes(num as u32) } @@ -113,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) -> DynamicArray + fn i64_to_bytes(num: i64) -> Array { Self::u64_to_bytes(num as u64) } @@ -128,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) -> DynamicArray + fn isize_to_bytes(num: isize) -> Array { let temp_num: usize; @@ -142,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) -> DynamicArray + fn f32_to_bytes(num: f32) -> Array { unsafe { @@ -156,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) -> DynamicArray + fn f64_to_bytes(num: f64) -> Array { unsafe { @@ -204,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) -> DynamicArray; + fn u16_to_bytes(num: u16) -> Array; /// Converts an unsigned 32-bit integer to bytes /// and places them into the given buffer. @@ -212,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) -> DynamicArray; + fn u32_to_bytes(num: u32) -> Array; /// Converts an unsigned 64-bit integer to bytes /// and places them into the given buffer. @@ -220,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) -> DynamicArray; + fn u64_to_bytes(num: u64) -> Array; /// Converts an unsigned integer to bytes /// and places them into the given buffer. @@ -232,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) -> DynamicArray; + fn usize_to_bytes(num: usize) -> Array; /// Converts a String to bytes @@ -252,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) -> DynamicArray; + fn string_to_bytes(string: String) -> Array; } diff --git a/src/endian.rs b/src/endian.rs index 9be8f1c..4f0866c 100644 --- a/src/endian.rs +++ b/src/endian.rs @@ -1,4 +1,4 @@ -use spellbook::components::DynamicArray; +use spellbook::components::Array; use ::byte_sized::ByteSized; use ::byte_sized::U64_BYTES; @@ -146,25 +146,25 @@ impl Converter for BigEndian } - fn u16_to_bytes(num: u16) -> DynamicArray + fn u16_to_bytes(num: u16) -> Array { // Unpack the value into it's byte form. unpack_big_endian!(num, u16::BYTES) } - fn u32_to_bytes(num: u32) -> DynamicArray + fn u32_to_bytes(num: u32) -> Array { // Unpack the value into it's byte form. unpack_big_endian!(num, u32::BYTES) } - fn u64_to_bytes(num: u64) -> DynamicArray + fn u64_to_bytes(num: u64) -> Array { // Unpack the value into it's byte form. unpack_big_endian!(num, u64::BYTES) } - fn usize_to_bytes(num: usize) -> DynamicArray + fn usize_to_bytes(num: usize) -> Array { // Unpack the value into it's byte form. unpack_big_endian!(num, usize::BYTES) @@ -206,11 +206,11 @@ impl Converter for BigEndian new_string } - fn string_to_bytes(string: String) -> DynamicArray + fn string_to_bytes(string: String) -> Array { let bytes: &[u8]; let byte_count: u64; - let mut buffer: DynamicArray; + let mut buffer: Array; // Turn the string into a byte array. bytes = string.as_bytes(); @@ -220,7 +220,7 @@ impl Converter for BigEndian byte_count = bytes.len() as u64; // Make sure the buffer has enough space for this string. - buffer = DynamicArray::with_capacity(bytes.len() + U64_BYTES); + buffer = Array::with_capacity(bytes.len() + U64_BYTES); // Add the count to the buffer. buffer.append(&mut BigEndian::u64_to_bytes(byte_count)); @@ -274,25 +274,25 @@ impl Converter for LittleEndian } - fn u16_to_bytes(num: u16) -> DynamicArray + fn u16_to_bytes(num: u16) -> Array { // Unpack the value into it's byte form. unpack_little_endian!(num, u16::BYTES) } - fn u32_to_bytes(num: u32) -> DynamicArray + fn u32_to_bytes(num: u32) -> Array { // Unpack the value into it's byte form. unpack_little_endian!(num, u32::BYTES) } - fn u64_to_bytes(num: u64) -> DynamicArray + fn u64_to_bytes(num: u64) -> Array { // Unpack the value into it's byte form. unpack_little_endian!(num, u64::BYTES) } - fn usize_to_bytes(num: usize) -> DynamicArray + fn usize_to_bytes(num: usize) -> Array { // Unpack the value into it's byte form. unpack_little_endian!(num, usize::BYTES) @@ -334,11 +334,11 @@ impl Converter for LittleEndian new_string } - fn string_to_bytes(string: String) -> DynamicArray + fn string_to_bytes(string: String) -> Array { let bytes: &[u8]; let byte_count: u64; - let mut buffer: DynamicArray; + let mut buffer: Array; // Turn the string into a byte array. bytes = string.as_bytes(); @@ -348,7 +348,7 @@ impl Converter for LittleEndian byte_count = bytes.len() as u64; // Make sure the buffer has enough space for this string. - buffer = DynamicArray::with_capacity(bytes.len() + U64_BYTES); + buffer = Array::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/macros.rs b/src/macros.rs index 30e3071..b227fb1 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: ::spellbook::components::DynamicArray; + let mut buffer: ::spellbook::components::Array; // Create an array with enough space for this value // and then bit shift the value into a buffer of bytes. - buffer = ::spellbook::components::DynamicArray::with_capacity($bytes); + buffer = ::spellbook::components::Array::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: ::spellbook::components::DynamicArray; + let mut buffer: ::spellbook::components::Array; // Create an array with enough space for this value // and then bit shift the value into a buffer of bytes. - buffer = ::spellbook::components::DynamicArray::with_capacity($bytes); + buffer = ::spellbook::components::Array::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: ::spellbook::components::DynamicArray; + let buffer: ::spellbook::components::Array; // 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: ::spellbook::components::DynamicArray; + let buffer: ::spellbook::components::Array; // Convert the little endian value to bytes. buffer = unpack_little_endian!($value, $bytes); diff --git a/src/transmutable.rs b/src/transmutable.rs index 1cf5bb7..723f4a8 100644 --- a/src/transmutable.rs +++ b/src/transmutable.rs @@ -1,10 +1,10 @@ -use spellbook::components::DynamicArray; +use spellbook::components::Array; #[cfg(feature="convert_sigils")] use sigils::{Zero, Number, Real}; #[cfg(feature="convert_sigils")] -use sigils::vector::{DynamicArraytor, DynamicArraytor2, DynamicArraytor3, DynamicArraytor4}; +use sigils::vector::{Arraytor, Arraytor2, Arraytor3, Arraytor4}; #[cfg(feature="convert_sigils")] use sigils::quaternion::Quaternion; @@ -35,14 +35,14 @@ pub trait Transmutable: Sized /// Transmute this type to an array of bytes in /// the Platform's endian. - fn to_bytes(self) -> DynamicArray + 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) -> DynamicArray + fn to_endian_bytes(self, endianess: Endianess) -> Array { self.as_endian_bytes(endianess) } @@ -50,14 +50,14 @@ pub trait Transmutable: Sized /// Transmute this type to an array of bytes in /// the Platform's endian. - fn as_bytes(&self) -> DynamicArray + fn as_bytes(&self) -> Array { 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) -> DynamicArray; + fn as_endian_bytes(&self, endianess: Endianess) -> Array; /// Get the current size of this Transmutable in bytes. @@ -149,7 +149,7 @@ impl Transmutable for u8 } #[allow(unused_variables)] - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // A single byte has no endian form. vec![*self] @@ -173,7 +173,7 @@ impl Transmutable for u16 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u16) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Return the Endianess conversion. handle_endianess_to_bytes!(self, endianess, u16_to_bytes) @@ -197,7 +197,7 @@ impl Transmutable for u32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u32) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, u32_to_bytes) @@ -221,7 +221,7 @@ impl Transmutable for u64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_u64) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, u64_to_bytes) @@ -245,7 +245,7 @@ impl Transmutable for usize handle_endianess_from_bytes!(buffer, endianess, bytes_to_usize) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, usize_to_bytes) @@ -270,7 +270,7 @@ impl Transmutable for i8 } #[allow(unused_variables)] - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { vec![*self as u8] } @@ -293,7 +293,7 @@ impl Transmutable for i16 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i16) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, i16_to_bytes) @@ -317,7 +317,7 @@ impl Transmutable for i32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i32) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, i32_to_bytes) @@ -341,7 +341,7 @@ impl Transmutable for i64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_i64) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, i64_to_bytes) @@ -365,7 +365,7 @@ impl Transmutable for isize handle_endianess_from_bytes!(buffer, endianess, bytes_to_isize) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, isize_to_bytes) @@ -389,7 +389,7 @@ impl Transmutable for f32 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f32) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, f32_to_bytes) @@ -413,7 +413,7 @@ impl Transmutable for f64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. handle_endianess_to_bytes!(self, endianess, f64_to_bytes) @@ -433,7 +433,7 @@ impl Transmutable for String handle_endianess_from_bytes!(buffer, endianess, bytes_to_string) } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { // Convert this to bytes and add it to the buffer. // We are not using the macro because *String is a str. @@ -468,17 +468,17 @@ impl Transmutable for String } #[cfg(feature="convert_sigils")] -impl Transmutable for DynamicArraytor2 where T: Number + ByteSized + Transmutable +impl Transmutable for Arraytor2 where T: Number + ByteSized + Transmutable { fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; let num_bytes: usize; - let mut vec: DynamicArraytor2; + let mut vec: Arraytor2; // Determine the number of bytes requires to - // represent a DynamicArraytor2. - vec = DynamicArraytor2::::zero(); + // represent a Arraytor2. + vec = Arraytor2::::zero(); byte_size = T::get_byte_size(); num_bytes = byte_size * vec.get_size() as usize; @@ -494,20 +494,20 @@ impl Transmutable for DynamicArraytor2 where T: Number + ByteSized + Trans vec } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { let byte_size: usize; let num_bytes: usize; - let mut buffer: DynamicArray; + let mut buffer: Array; // Determine the number of bytes requires to - // represent a DynamicArraytor2. + // represent a Arraytor2. 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 = DynamicArray::with_capacity(num_bytes); + buffer = Array::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.x.as_endian_bytes(endianess)); @@ -524,17 +524,17 @@ impl Transmutable for DynamicArraytor2 where T: Number + ByteSized + Trans } #[cfg(feature="convert_sigils")] -impl Transmutable for DynamicArraytor3 where T: Number + ByteSized + Transmutable +impl Transmutable for Arraytor3 where T: Number + ByteSized + Transmutable { fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; let num_bytes: usize; - let mut vec: DynamicArraytor3; + let mut vec: Arraytor3; // Determine the number of bytes requires to - // represent a DynamicArraytor3. - vec = DynamicArraytor3::::zero(); + // represent a Arraytor3. + vec = Arraytor3::::zero(); byte_size = T::get_byte_size(); num_bytes = byte_size * vec.get_size() as usize; @@ -552,20 +552,20 @@ impl Transmutable for DynamicArraytor3 where T: Number + ByteSized + Trans vec } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { let byte_size: usize; let num_bytes: usize; - let mut buffer: DynamicArray; + let mut buffer: Array; // Determine the number of bytes requires to - // represent a DynamicArraytor3. + // represent a Arraytor3. 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 = DynamicArray::with_capacity(num_bytes); + buffer = Array::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.x.as_endian_bytes(endianess)); @@ -583,17 +583,17 @@ impl Transmutable for DynamicArraytor3 where T: Number + ByteSized + Trans } #[cfg(feature="convert_sigils")] -impl Transmutable for DynamicArraytor4 where T: Number + ByteSized + Transmutable +impl Transmutable for Arraytor4 where T: Number + ByteSized + Transmutable { fn from_endian_bytes(buffer: &[u8], endianess: Endianess) -> Self { let byte_size: usize; let num_bytes: usize; - let mut vec: DynamicArraytor4; + let mut vec: Arraytor4; // Determine the number of bytes requires to - // represent a DynamicArraytor4. - vec = DynamicArraytor4::::zero(); + // represent a Arraytor4. + vec = Arraytor4::::zero(); byte_size = T::get_byte_size(); num_bytes = byte_size * vec.get_size() as usize; @@ -613,20 +613,20 @@ impl Transmutable for DynamicArraytor4 where T: Number + ByteSized + Trans vec } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { let byte_size: usize; let num_bytes: usize; - let mut buffer: DynamicArray; + let mut buffer: Array; // Determine the number of bytes requires to - // represent a DynamicArraytor4. + // represent a Arraytor4. 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 = DynamicArray::with_capacity(num_bytes); + buffer = Array::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.x.as_endian_bytes(endianess)); @@ -667,16 +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 = - DynamicArraytor3::::from_endian_bytes(&buffer[byte_size..num_bytes], + Arraytor3::::from_endian_bytes(&buffer[byte_size..num_bytes], endianess); quat } - fn as_endian_bytes(&self, endianess: Endianess) -> DynamicArray + fn as_endian_bytes(&self, endianess: Endianess) -> Array { let byte_size: usize; let num_bytes: usize; - let mut buffer: DynamicArray; + let mut buffer: Array; // Determine the number of bytes requires to // represent a Quaternion. @@ -685,7 +685,7 @@ impl Transmutable for Quaternion // Make sure that there is enough space to store // the bytes from this type. - buffer = DynamicArray::with_capacity(num_bytes); + buffer = Array::with_capacity(num_bytes); // Convert this to bytes and add it to the buffer. buffer.append(&mut self.scalar.as_endian_bytes(endianess));