From d9a3e21aec0ed9b3aa7af59ee9e069e429b91784 Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Tue, 5 Jan 2016 23:42:08 -0500 Subject: [PATCH] Fixed the example and tests to use the new Converter trait. Transmutable was changed to Converter. This needed to be reflected in the example and tests. Also, fixed some comments in the new transmutable module. --- examples/convert_f32.rs | 7 ++----- src/transmutable.rs | 9 ++++++++- tests/lib.rs | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/convert_f32.rs b/examples/convert_f32.rs index dd5b209..86c826f 100644 --- a/examples/convert_f32.rs +++ b/examples/convert_f32.rs @@ -3,21 +3,18 @@ extern crate alchemy; -use std::f32; - -use alchemy::{PlatformEndian, Transmutable}; +use alchemy::{Converter, PlatformEndian}; pub fn main() { let num: f32; - let mut final_num: f32; + let final_num: f32; let mut buffer: [u8; 4]; // Initialize the variables. num = 6.291985f32; - final_num = f32::NAN; buffer = [0u8; 4]; println!("Converting the value {} into and out of an array of bytes.", num); diff --git a/src/transmutable.rs b/src/transmutable.rs index d499e1d..0d9a575 100644 --- a/src/transmutable.rs +++ b/src/transmutable.rs @@ -6,7 +6,9 @@ use ::endian::{BigEndian, LittleEndian, PlatformEndian, Endianess}; -/// Handles the repetative +/// Handles the repetative endianess matching +/// for the primitive number types when converting +/// a number to bytes. macro_rules! handle_endianess_to_bytes { ($buffer: ident, $val: ident, $endianess: ident, $func: ident) => @@ -36,6 +38,9 @@ macro_rules! handle_endianess_to_bytes } } +/// Handles the repetative endianess matching +/// for the primitive number types when converting +/// a number from bytes. macro_rules! handle_endianess_from_bytes { ($buffer: ident, $endianess: ident, $func: ident) => @@ -358,3 +363,5 @@ impl Transmutable for f64 handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64) } } + + diff --git a/tests/lib.rs b/tests/lib.rs index 931262d..a29bbdf 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -48,7 +48,7 @@ macro_rules! full_check_impl { use rand::ThreadRng; use rand::distributions::{IndependentSample, Range}; - use alchemy::{BigEndian, LittleEndian, Transmutable}; + use alchemy::{Converter, BigEndian, LittleEndian}; let range: Range<$T>; let mut rng: ThreadRng; @@ -115,7 +115,7 @@ macro_rules! overflow_impl { use std::num::Zero; - use alchemy::{BigEndian, LittleEndian, Transmutable}; + use alchemy::{Converter, BigEndian, LittleEndian};