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.
This commit is contained in:
Jason Travis Smith 2016-01-05 23:42:08 -05:00
parent e7f2f252fa
commit d9a3e21aec
3 changed files with 12 additions and 8 deletions

View File

@ -3,21 +3,18 @@
extern crate alchemy; extern crate alchemy;
use std::f32; use alchemy::{Converter, PlatformEndian};
use alchemy::{PlatformEndian, Transmutable};
pub fn main() pub fn main()
{ {
let num: f32; let num: f32;
let mut final_num: f32; let final_num: f32;
let mut buffer: [u8; 4]; let mut buffer: [u8; 4];
// Initialize the variables. // Initialize the variables.
num = 6.291985f32; num = 6.291985f32;
final_num = f32::NAN;
buffer = [0u8; 4]; buffer = [0u8; 4];
println!("Converting the value {} into and out of an array of bytes.", num); println!("Converting the value {} into and out of an array of bytes.", num);

View File

@ -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 macro_rules! handle_endianess_to_bytes
{ {
($buffer: ident, $val: ident, $endianess: ident, $func: ident) => ($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 macro_rules! handle_endianess_from_bytes
{ {
($buffer: ident, $endianess: ident, $func: ident) => ($buffer: ident, $endianess: ident, $func: ident) =>
@ -358,3 +363,5 @@ impl Transmutable for f64
handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64) handle_endianess_from_bytes!(buffer, endianess, bytes_to_f64)
} }
} }

View File

@ -48,7 +48,7 @@ macro_rules! full_check_impl
{ {
use rand::ThreadRng; use rand::ThreadRng;
use rand::distributions::{IndependentSample, Range}; use rand::distributions::{IndependentSample, Range};
use alchemy::{BigEndian, LittleEndian, Transmutable}; use alchemy::{Converter, BigEndian, LittleEndian};
let range: Range<$T>; let range: Range<$T>;
let mut rng: ThreadRng; let mut rng: ThreadRng;
@ -115,7 +115,7 @@ macro_rules! overflow_impl
{ {
use std::num::Zero; use std::num::Zero;
use alchemy::{BigEndian, LittleEndian, Transmutable}; use alchemy::{Converter, BigEndian, LittleEndian};