Upgraded to latest sigils release.
This added the ability to more easily print Vectors and Quaternions. This also fixes some style issues. Missing documents will now cause warnings when building.
This commit is contained in:
parent
1374ff5e4a
commit
307118412b
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -33,7 +33,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "sigils"
|
name = "sigils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://gitlab.com/CyberMages/sigils.git#9306a73f9a0d03a15f0f870fee18024880c7cf2a"
|
source = "git+https://gitlab.com/CyberMages/sigils.git#e64c3b0fbecca351e0a078fefc4273a0f0b8e6ad"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
|
@ -71,9 +71,8 @@ pub fn main()
|
|||||||
|
|
||||||
println!("Transmuting a Quaternion:");
|
println!("Transmuting a Quaternion:");
|
||||||
|
|
||||||
println!("Converting the value [{1}, <{2}, {3}, {4}>] {0}",
|
println!("Converting the value {} into and out of an array of bytes.",
|
||||||
"into and out of an array of bytes.",
|
quat);
|
||||||
quat.scalar, quat.vector.x, quat.vector.y, quat.vector.z);
|
|
||||||
println!("Buffer starts as: {}", stringify_array(&buffer));
|
println!("Buffer starts as: {}", stringify_array(&buffer));
|
||||||
|
|
||||||
// Convert the Vector2 into an array of bytes.
|
// Convert the Vector2 into an array of bytes.
|
||||||
@ -83,7 +82,5 @@ pub fn main()
|
|||||||
|
|
||||||
// Convert the array of bytes into a Vector2.
|
// Convert the array of bytes into a Vector2.
|
||||||
final_quat = Quaternion::from_bytes(&buffer, endianess);
|
final_quat = Quaternion::from_bytes(&buffer, endianess);
|
||||||
println!("The buffer converts back to: [{}, <{}, {}, {}>]",
|
println!("The buffer converts back to: {}", final_quat);
|
||||||
final_quat.scalar, final_quat.vector.x,
|
|
||||||
final_quat.vector.y, final_quat.vector.z);
|
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ pub fn main()
|
|||||||
|
|
||||||
println!("Transmuting a Vector2:");
|
println!("Transmuting a Vector2:");
|
||||||
|
|
||||||
println!("Converting the value [{}, {}] into and out of an array of bytes.",
|
println!("Converting the value {} into and out of an array of bytes.",
|
||||||
vec.x, vec.y);
|
vec);
|
||||||
println!("Buffer starts as: {}", stringify_array(&buffer));
|
println!("Buffer starts as: {}", stringify_array(&buffer));
|
||||||
|
|
||||||
// Convert the Vector2 into an array of bytes.
|
// Convert the Vector2 into an array of bytes.
|
||||||
@ -82,5 +82,5 @@ pub fn main()
|
|||||||
|
|
||||||
// Convert the array of bytes into a Vector2.
|
// Convert the array of bytes into a Vector2.
|
||||||
final_vec = Vector2::from_bytes(&buffer, endianess);
|
final_vec = Vector2::from_bytes(&buffer, endianess);
|
||||||
println!("The buffer converts back to: [{}, {}]", final_vec.x, final_vec.y);
|
println!("The buffer converts back to: {}", final_vec);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ pub trait ByteSized
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
macro_rules! byte_sized_impl
|
macro_rules! byte_sized_impl
|
||||||
{
|
{
|
||||||
($(($varType: ty, $numBytes: expr))*) =>
|
($(($varType: ty, $numBytes: expr))*) =>
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
//! The Alchemy library is a data type to byte converter library.
|
||||||
|
//! Alchemy handles converting numbers to and from bytes
|
||||||
|
//! in either big or little endian format.
|
||||||
#![feature(associated_consts)]
|
#![feature(associated_consts)]
|
||||||
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
extern crate sigils;
|
extern crate sigils;
|
||||||
|
|
||||||
|
@ -8,6 +8,20 @@ use ::endian::{BigEndian, LittleEndian, PlatformEndian, 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
|
||||||
|
{
|
||||||
|
/// Transmute this type to an array of bytes.
|
||||||
|
fn to_bytes(&self, buffer: &mut [u8], endianess: Endianess);
|
||||||
|
|
||||||
|
/// Transmute an array of bytes to this type.
|
||||||
|
fn from_bytes(buffer: &[u8], endianess: Endianess) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Handles the repetative endianess matching
|
/// Handles the repetative endianess matching
|
||||||
/// for the primitive number types when converting
|
/// for the primitive number types when converting
|
||||||
/// a number to bytes.
|
/// a number to bytes.
|
||||||
@ -69,20 +83,6 @@ macro_rules! handle_endianess_from_bytes
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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
|
|
||||||
{
|
|
||||||
/// Transmute this type to an array of bytes.
|
|
||||||
fn to_bytes(&self, buffer: &mut [u8], endianess: Endianess);
|
|
||||||
|
|
||||||
/// Transmute an array of bytes to this type.
|
|
||||||
fn from_bytes(buffer: &[u8], endianess: Endianess) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Transmutable for u8
|
impl Transmutable for u8
|
||||||
{
|
{
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
|
@ -44,24 +44,24 @@ macro_rules! create_thread
|
|||||||
///
|
///
|
||||||
macro_rules! full_check_impl
|
macro_rules! full_check_impl
|
||||||
{
|
{
|
||||||
($T: ident, $read_func: ident, $write_func: ident, $numBytes: expr) =>
|
($varType: ident, $read_func: ident, $write_func: ident, $numBytes: expr) =>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
use std::$T;
|
use std::$varType;
|
||||||
use rand::ThreadRng;
|
use rand::ThreadRng;
|
||||||
use rand::distributions::{IndependentSample, Range};
|
use rand::distributions::{IndependentSample, Range};
|
||||||
use alchemy::{Converter, BigEndian, LittleEndian};
|
use alchemy::{Converter, BigEndian, LittleEndian};
|
||||||
|
|
||||||
let range: Range<$T>;
|
let range: Range<$varType>;
|
||||||
let mut rng: ThreadRng;
|
let mut rng: ThreadRng;
|
||||||
|
|
||||||
rng = rand::thread_rng();
|
rng = rand::thread_rng();
|
||||||
range = Range::new($T::MIN, $T::MAX);
|
range = Range::new($varType::MIN, $varType::MAX);
|
||||||
for _ in 0..EXHAUSTIVE_RUNS
|
for _ in 0..EXHAUSTIVE_RUNS
|
||||||
{
|
{
|
||||||
let val: $T;
|
let val: $varType;
|
||||||
let final_big_val: $T;
|
let final_big_val: $varType;
|
||||||
let final_little_val: $T;
|
let final_little_val: $varType;
|
||||||
let mut buffer: [u8; $numBytes];
|
let mut buffer: [u8; $numBytes];
|
||||||
|
|
||||||
buffer = [0u8; $numBytes];
|
buffer = [0u8; $numBytes];
|
||||||
@ -90,20 +90,21 @@ macro_rules! full_check_impl
|
|||||||
///
|
///
|
||||||
macro_rules! full_check
|
macro_rules! full_check
|
||||||
{
|
{
|
||||||
($func_name: ident, $T: ident, $read_func: ident, $write_func: ident) =>
|
($func_name: ident, $varType: ident, $read_func: ident,
|
||||||
|
$write_func: ident) =>
|
||||||
{
|
{
|
||||||
fn $func_name() -> bool
|
fn $func_name() -> bool
|
||||||
{
|
{
|
||||||
full_check_impl!($T, $read_func, $write_func, $T::BYTES)
|
full_check_impl!($varType, $read_func, $write_func, $varType::BYTES)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($func_name: ident, $T: ident,
|
($func_name: ident, $varType: ident,
|
||||||
$read_func: ident, $write_func: ident, $numBytes: expr) =>
|
$read_func: ident, $write_func: ident, $numBytes: expr) =>
|
||||||
{
|
{
|
||||||
fn $func_name() -> bool
|
fn $func_name() -> bool
|
||||||
{
|
{
|
||||||
full_check_impl!($T, $read_func, $write_func, $numBytes)
|
full_check_impl!($varType, $read_func, $write_func, $numBytes)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -111,7 +112,7 @@ macro_rules! full_check
|
|||||||
/// This should only be called by the macro below.
|
/// This should only be called by the macro below.
|
||||||
macro_rules! overflow_impl
|
macro_rules! overflow_impl
|
||||||
{
|
{
|
||||||
($numBytes: expr, $T: ident,
|
($numBytes: expr, $varType: ident,
|
||||||
$read_func: ident, $write_func: ident) =>
|
$read_func: ident, $write_func: ident) =>
|
||||||
{
|
{
|
||||||
use alchemy::{Converter, BigEndian, LittleEndian};
|
use alchemy::{Converter, BigEndian, LittleEndian};
|
||||||
@ -146,7 +147,7 @@ macro_rules! overflow_impl
|
|||||||
let mut buffer: [u8; $numBytes - 1];
|
let mut buffer: [u8; $numBytes - 1];
|
||||||
|
|
||||||
buffer = [0u8; $numBytes - 1];
|
buffer = [0u8; $numBytes - 1];
|
||||||
BigEndian::$write_func(&mut buffer, $T::zero());
|
BigEndian::$write_func(&mut buffer, $varType::zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -156,7 +157,7 @@ macro_rules! overflow_impl
|
|||||||
let mut buffer: [u8; $numBytes - 1];
|
let mut buffer: [u8; $numBytes - 1];
|
||||||
|
|
||||||
buffer = [0u8; $numBytes - 1];
|
buffer = [0u8; $numBytes - 1];
|
||||||
LittleEndian::$write_func(&mut buffer, $T::zero());
|
LittleEndian::$write_func(&mut buffer, $varType::zero());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -164,14 +165,14 @@ macro_rules! overflow_impl
|
|||||||
/// This macro tries to test for buffer overflow happening.
|
/// This macro tries to test for buffer overflow happening.
|
||||||
macro_rules! test_buffer_overflow
|
macro_rules! test_buffer_overflow
|
||||||
{
|
{
|
||||||
($mod_name: ident, $T: ident,
|
($mod_name: ident, $varType: ident,
|
||||||
$read_func: ident, $write_func: ident, $numBytes: ident) =>
|
$read_func: ident, $write_func: ident, $numBytes: ident) =>
|
||||||
{
|
{
|
||||||
mod $mod_name
|
mod $mod_name
|
||||||
{
|
{
|
||||||
use alchemy::$numBytes;
|
use alchemy::$numBytes;
|
||||||
|
|
||||||
overflow_impl!($numBytes, $T, $read_func, $write_func);
|
overflow_impl!($numBytes, $varType, $read_func, $write_func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user