diff --git a/Cargo.toml b/Cargo.toml index 7046fa1..4a8fcb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ license = "" repository = "https://gitlab.com/CyberMages/Core/alchemy.git" documentation = "" keywords = ["converter", "binary"] +edition = "2018" [features] diff --git a/src/converter.rs b/src/converter.rs index 6d6a984..ad38daa 100644 --- a/src/converter.rs +++ b/src/converter.rs @@ -1,9 +1,11 @@ use std::mem; +use weave::attempt; + use spellbook::components::Array; -use ::byte_sized::ByteSized; -use ::conversion_error::ConversionError; +use crate::byte_sized::ByteSized; +use crate::conversion_error::ConversionError; /// Describes types that can convert Numbers into bytes, @@ -17,7 +19,7 @@ pub trait Converter /// enough information to convert. fn bytes_to_i16(buffer: &[u8]) -> Result { - Ok(try!(Self::bytes_to_u16(buffer)) as i16) + Ok(attempt!(Self::bytes_to_u16(buffer)) as i16) } /// Converts an array of bytes to a signed 32-bit integer. @@ -27,7 +29,7 @@ pub trait Converter /// enough information to convert. fn bytes_to_i32(buffer: &[u8]) -> Result { - Ok(try!(Self::bytes_to_u32(buffer)) as i32) + Ok(attempt!(Self::bytes_to_u32(buffer)) as i32) } /// Converts an array of bytes to a signed 64-bit integer. @@ -37,7 +39,7 @@ pub trait Converter /// enough information to convert. fn bytes_to_i64(buffer: &[u8]) -> Result { - Ok(try!(Self::bytes_to_u64(buffer)) as i64) + Ok(attempt!(Self::bytes_to_u64(buffer)) as i64) } /// Converts an array of bytes to a signed integer. @@ -54,7 +56,7 @@ pub trait Converter check_length!(buffer, isize::BYTES, u64::BYTES); - temp_num = try!(Self::bytes_to_usize(buffer)) as u64; + temp_num = attempt!(Self::bytes_to_usize(buffer)) as u64; Ok(add_sign(temp_num, buffer.len() as u8) as isize) } @@ -67,7 +69,7 @@ pub trait Converter { unsafe { - Ok(mem::transmute::(try!(Self::bytes_to_u32(buffer)))) + Ok(mem::transmute::(attempt!(Self::bytes_to_u32(buffer)))) } } @@ -80,7 +82,7 @@ pub trait Converter { unsafe { - Ok(mem::transmute::(try!(Self::bytes_to_u64(buffer)))) + Ok(mem::transmute::(attempt!(Self::bytes_to_u64(buffer)))) } } diff --git a/src/endian.rs b/src/endian.rs index 0e9826d..d517560 100644 --- a/src/endian.rs +++ b/src/endian.rs @@ -1,10 +1,14 @@ +use scribe::*; + +use weave::attempt; + use spellbook::components::Array; -use ::byte_sized::ByteSized; -use ::byte_sized::U64_BYTES; -use ::conversion_error::ConversionError; -use ::converter::Converter; -use ::transmutable::Transmutable; +use crate::byte_sized::ByteSized; +use crate::byte_sized::U64_BYTES; +use crate::conversion_error::ConversionError; +use crate::converter::Converter; +use crate::transmutable::Transmutable; @@ -166,7 +170,7 @@ impl Converter for BigEndian // Strings start with the size of bytes to read as // a u64. So read that in and then we know how many // bytes make up the string. - byte_count = try!(BigEndian::bytes_to_u64(&buffer[0..U64_BYTES])); + byte_count = attempt!(BigEndian::bytes_to_u64(&buffer[0..U64_BYTES])); if byte_count > 0 { @@ -275,7 +279,7 @@ impl Converter for LittleEndian // Strings start with the size of bytes to read as // a u64. So read that in and then we know how many // bytes make up the string. - byte_count = try!(LittleEndian::bytes_to_u64(&buffer[0..U64_BYTES])); + byte_count = attempt!(LittleEndian::bytes_to_u64(&buffer[0..U64_BYTES])); if byte_count > 0 { @@ -383,7 +387,7 @@ pub fn network_to_platform_order(val: T) -> Result } else { - converted_val = try!(T::from_endian_bytes(val.as_bytes().as_slice(), + converted_val = attempt!(T::from_endian_bytes(val.as_bytes().as_slice(), Endianess::Network)); } @@ -405,7 +409,7 @@ pub fn platform_to_network_order(val: T) -> Result } else { - converted_val = try!(T::from_endian_bytes(val.as_bytes().as_slice(), + converted_val = attempt!(T::from_endian_bytes(val.as_bytes().as_slice(), Endianess::Network)); } diff --git a/src/lib.rs b/src/lib.rs index 4bb6f8b..956c304 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,16 +8,13 @@ -#[macro_use] extern crate scribe; - extern crate weave; +extern crate spellbook; #[cfg(feature="sigils")] extern crate sigils; -extern crate spellbook; - #[macro_use] @@ -31,15 +28,15 @@ mod transmutable; -pub use ::byte_sized::ByteSized; -pub use ::byte_sized::{U8_BYTES, U16_BYTES, U32_BYTES, U64_BYTES, USIZE_BYTES}; -pub use ::byte_sized::{I8_BYTES, I16_BYTES, I32_BYTES, I64_BYTES, ISIZE_BYTES}; -pub use ::byte_sized::{F32_BYTES, F64_BYTES}; -pub use ::byte_sized::get_byte_size_of_string; -pub use ::conversion_error::ConversionError; -pub use ::converter::Converter; -pub use ::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian}; -pub use ::endian::Endianess; -pub use ::endian::{network_to_platform_order, platform_to_network_order}; -pub use ::endian::{get_network_endianess, get_platform_endianess}; -pub use ::transmutable::Transmutable; +pub use crate::byte_sized::ByteSized; +pub use crate::byte_sized::{U8_BYTES, U16_BYTES, U32_BYTES, U64_BYTES, USIZE_BYTES}; +pub use crate::byte_sized::{I8_BYTES, I16_BYTES, I32_BYTES, I64_BYTES, ISIZE_BYTES}; +pub use crate::byte_sized::{F32_BYTES, F64_BYTES}; +pub use crate::byte_sized::get_byte_size_of_string; +pub use crate::conversion_error::ConversionError; +pub use crate::converter::Converter; +pub use crate::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian}; +pub use crate::endian::Endianess; +pub use crate::endian::{network_to_platform_order, platform_to_network_order}; +pub use crate::endian::{get_network_endianess, get_platform_endianess}; +pub use crate::transmutable::Transmutable; diff --git a/src/transmutable.rs b/src/transmutable.rs index 78e1f6a..afa6460 100644 --- a/src/transmutable.rs +++ b/src/transmutable.rs @@ -9,11 +9,11 @@ use sigils::vector::{Vector, Vector2, Vector3, Vector4}; #[cfg(feature="convert_sigils")] use sigils::quaternion::Quaternion; -use ::byte_sized::{ByteSized, get_byte_size_of_string}; -use ::conversion_error::ConversionError; -use ::converter::Converter; -use ::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian}; -use ::endian::Endianess; +use crate::byte_sized::{ByteSized, get_byte_size_of_string}; +use crate::conversion_error::ConversionError; +use crate::converter::Converter; +use crate::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian}; +use crate::endian::Endianess; @@ -465,9 +465,9 @@ impl Transmutable for Vector2 where T: Number + ByteSized + Transmutable check_length!(buffer >= num_bytes); // Convert the given bytes to this type and return it. - vec.x = try!(T::from_endian_bytes(&buffer[0..T::BYTES], + vec.x = attempt!(T::from_endian_bytes(&buffer[0..T::BYTES], endianess)); - vec.y = try!(T::from_endian_bytes(&buffer[T::BYTES..num_bytes], + vec.y = attempt!(T::from_endian_bytes(&buffer[T::BYTES..num_bytes], endianess)); Ok(vec) } @@ -516,11 +516,11 @@ impl Transmutable for Vector3 where T: Number + ByteSized + Transmutable check_length!(buffer >= num_bytes); // Convert the given bytes to this type and return it. - vec.x = try!(T::from_endian_bytes(&buffer[0..T::BYTES], + vec.x = attempt!(T::from_endian_bytes(&buffer[0..T::BYTES], endianess)); - vec.y = try!(T::from_endian_bytes(&buffer[T::BYTES..(T::BYTES * 2)], + vec.y = attempt!(T::from_endian_bytes(&buffer[T::BYTES..(T::BYTES * 2)], endianess)); - vec.z = try!(T::from_endian_bytes(&buffer[(T::BYTES * 2)..num_bytes], + vec.z = attempt!(T::from_endian_bytes(&buffer[(T::BYTES * 2)..num_bytes], endianess)); Ok(vec) } @@ -570,13 +570,13 @@ impl Transmutable for Vector4 where T: Number + ByteSized + Transmutable check_length!(buffer >= num_bytes); // Convert the given bytes to this type and return it. - vec.x = try!(T::from_endian_bytes(&buffer[0..T::BYTES], + vec.x = attempt!(T::from_endian_bytes(&buffer[0..T::BYTES], endianess)); - vec.y = try!(T::from_endian_bytes(&buffer[T::BYTES..(T::BYTES * 2)], + vec.y = attempt!(T::from_endian_bytes(&buffer[T::BYTES..(T::BYTES * 2)], endianess)); - vec.z = try!(T::from_endian_bytes(&buffer[(T::BYTES*2)..(T::BYTES*3)], + vec.z = attempt!(T::from_endian_bytes(&buffer[(T::BYTES*2)..(T::BYTES*3)], endianess)); - vec.w = try!(T::from_endian_bytes(&buffer[(T::BYTES * 3)..num_bytes], + vec.w = attempt!(T::from_endian_bytes(&buffer[(T::BYTES * 3)..num_bytes], endianess)); Ok(vec) } @@ -630,10 +630,10 @@ impl Transmutable for Quaternion check_length!(buffer >= num_bytes); // Convert the given bytes to this type and return it. - quat.scalar = try!(T::from_endian_bytes(&buffer[0..T::BYTES], + quat.scalar = attempt!(T::from_endian_bytes(&buffer[0..T::BYTES], endianess)); quat.vector = - try!(Vector3::::from_endian_bytes(&buffer[T::BYTES..num_bytes], + attempt!(Vector3::::from_endian_bytes(&buffer[T::BYTES..num_bytes], endianess)); Ok(quat) }