From 0f9b3b56c53d3747b0e781ba089eeb225fb6e234 Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Sun, 29 Apr 2018 04:22:42 -0400 Subject: [PATCH] Updated the library to use the new Array interface. --- src/macros.rs | 4 ++-- src/transmutable.rs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index ebf1031..001002e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -105,7 +105,7 @@ macro_rules! unpack_big_endian buffer = ::spellbook::components::Array::with_capacity($bytes); for i in 0..$bytes { - buffer.push(($value >> (($bytes - i) - 1) * 8) as u8); + buffer.insert_element(($value >> (($bytes - i) - 1) * 8) as u8); } // Return the buffer of bytes that represent this value. @@ -127,7 +127,7 @@ macro_rules! unpack_little_endian buffer = ::spellbook::components::Array::with_capacity($bytes); for i in 0..$bytes { - buffer.push(($value >> (i * 8)) as u8); + buffer.insert_element(($value >> (i * 8)) as u8); } // Return the buffer of bytes that represent this value. diff --git a/src/transmutable.rs b/src/transmutable.rs index d419bc4..78e1f6a 100644 --- a/src/transmutable.rs +++ b/src/transmutable.rs @@ -151,8 +151,12 @@ impl Transmutable for u8 #[allow(unused_variables)] fn as_endian_bytes(&self, endianess: Endianess) -> Array { - // A single byte has no endian form. - vec![*self] + let mut bytes: Array; + + bytes = Array::with_capacity(1usize); + bytes.insert_element(*self); + + bytes } fn determine_byte_size(&self) -> usize @@ -259,7 +263,12 @@ impl Transmutable for i8 #[allow(unused_variables)] fn as_endian_bytes(&self, endianess: Endianess) -> Array { - vec![*self as u8] + let mut bytes: Array; + + bytes = Array::with_capacity(1usize); + bytes.insert_element(*self as u8); + + bytes } fn determine_byte_size(&self) -> usize