Rust no longer requires extern crate calls as of the 2018 update.

Update all the examples to work with the spellbook Array class as well.
This commit is contained in:
Myrddin Dundragon 2019-01-20 20:38:42 -05:00
parent 3e4094a50c
commit eec868b406
7 changed files with 41 additions and 66 deletions

View File

@ -1,9 +1,7 @@
extern crate weave;
extern crate alchemy;
use weave::Error; use weave::Error;
use spellbook::components::Array;
use alchemy::{Converter, Endianess, PlatformEndian, Transmutable}; use alchemy::{Converter, Endianess, PlatformEndian, Transmutable};
@ -11,11 +9,11 @@ use alchemy::{Converter, Endianess, PlatformEndian, Transmutable};
fn use_converter() fn use_converter()
{ {
let num: f32; let num: f32;
let mut buffer: Vec<u8>; let mut buffer: Array<u8>;
// Initialize the variables. // Initialize the variables.
num = 6.291985f32; num = 6.291985f32;
buffer = Vec::new(); buffer = Array::new();
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);
println!("Buffer starts as: {}", stringify_array(buffer.as_slice())); println!("Buffer starts as: {}", stringify_array(buffer.as_slice()));
@ -44,11 +42,11 @@ pub fn use_transmutable()
{ {
let num: f32; let num: f32;
let endianess: Endianess; let endianess: Endianess;
let mut buffer: Vec<u8>; let mut buffer: Array<u8>;
// Initialize the variables. // Initialize the variables.
num = 6.291985f32; num = 6.291985f32;
buffer = Vec::new(); buffer = Array::new();
endianess = Endianess::Platform; endianess = Endianess::Platform;
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

@ -1,18 +1,14 @@
//! Run this example with --feature convert_sigils //! Run this example with --feature convert_sigils
extern crate weave;
extern crate alchemy;
extern crate sigils;
use weave::Error; use weave::Error;
use alchemy::F64_BYTES; use spellbook::components::Array;
use alchemy::{Endianess, Transmutable};
use sigils::quaternion::Quaternion; use sigils::quaternion::Quaternion;
use alchemy::F64_BYTES;
use alchemy::{Endianess, Transmutable};
/// The size of 4 f64 Real numbers. /// The size of 4 f64 Real numbers.
@ -65,11 +61,11 @@ pub fn main()
{ {
let quat: Quaternion<f64>; let quat: Quaternion<f64>;
let endianess: Endianess; let endianess: Endianess;
let mut buffer: Vec<u8>; let mut buffer: Array<u8>;
// Initialize the variables. // Initialize the variables.
quat = Quaternion::<f64>::from_values(6.29f64, 1.9f64, 8.5f64, 7.11f64); quat = Quaternion::<f64>::from_values(6.29f64, 1.9f64, 8.5f64, 7.11f64);
buffer = Vec::with_capacity(SIZE_OF_QUATERNION); buffer = Array::with_capacity(SIZE_OF_QUATERNION);
endianess = Endianess::Platform; endianess = Endianess::Platform;
println!("Transmuting a Quaternion:"); println!("Transmuting a Quaternion:");
@ -78,12 +74,12 @@ pub fn main()
quat); quat);
println!("Buffer starts as: {}", stringify_array(buffer.as_slice())); println!("Buffer starts as: {}", stringify_array(buffer.as_slice()));
// Convert the Vector2 into an array of bytes. // Convert the Arraytor2 into an array of bytes.
buffer = quat.as_endian_bytes(endianess); buffer = quat.as_endian_bytes(endianess);
println!("Buffer contains: {}", stringify_array(buffer.as_slice())); println!("Buffer contains: {}", stringify_array(buffer.as_slice()));
// Convert the array of bytes into a Vector2. // Convert the array of bytes into a Arraytor2.
match Quaternion::<f64>::from_endian_bytes(buffer.as_slice(), endianess) match Quaternion::<f64>::from_endian_bytes(buffer.as_slice(), endianess)
{ {
Ok(final_quat) => Ok(final_quat) =>

View File

@ -1,11 +1,7 @@
extern crate weave;
extern crate alchemy;
use weave::Error; use weave::Error;
use spellbook::components::Array;
use alchemy::{Converter, Endianess, PlatformEndian, Transmutable}; use alchemy::{Converter, Endianess, PlatformEndian, Transmutable};
use alchemy::platform_to_network_order; use alchemy::platform_to_network_order;
@ -14,11 +10,11 @@ use alchemy::platform_to_network_order;
fn use_converter() fn use_converter()
{ {
let num: u16; let num: u16;
let mut buffer: Vec<u8>; let mut buffer: Array<u8>;
// Initialize the variables. // Initialize the variables.
num = 32832u16; num = 32832u16;
buffer = Vec::new(); buffer = Array::new();
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);
println!("Buffer starts as: {}", stringify_array(buffer.as_slice())); println!("Buffer starts as: {}", stringify_array(buffer.as_slice()));
@ -47,11 +43,11 @@ pub fn use_transmutable()
{ {
let num: u16; let num: u16;
let endianess: Endianess; let endianess: Endianess;
let mut buffer: Vec<u8>; let mut buffer: Array<u8>;
// Initialize the variables. // Initialize the variables.
num = 32832u16; num = 32832u16;
buffer = Vec::new(); buffer = Array::new();
endianess = Endianess::Platform; endianess = Endianess::Platform;
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

@ -1,16 +1,12 @@
extern crate weave;
extern crate alchemy;
extern crate sigils;
use weave::Error; use weave::Error;
use spellbook::components::Array;
use sigils::vector::Vector2;
use alchemy::U64_BYTES; use alchemy::U64_BYTES;
use alchemy::{Endianess, Transmutable}; use alchemy::{Endianess, Transmutable};
use sigils::vector::Vector2;
/// The size of 2 u64 whole numbers. /// The size of 2 u64 whole numbers.
@ -63,11 +59,11 @@ pub fn main()
{ {
let vec: Vector2<u64>; let vec: Vector2<u64>;
let endianess: Endianess; let endianess: Endianess;
let mut buffer: Vec<u8>; let mut buffer: Array<u8>;
// Initialize the variables. // Initialize the variables.
vec = Vector2::<u64>::new(629u64, 1985u64); vec = Vector2::<u64>::new(629u64, 1985u64);
buffer = Vec::with_capacity(SIZE_OF_VECTOR_2); buffer = Array::with_capacity(SIZE_OF_VECTOR_2);
endianess = Endianess::Platform; endianess = Endianess::Platform;
println!("Transmuting a Vector2:"); println!("Transmuting a Vector2:");

View File

@ -1,7 +1,3 @@
extern crate alchemy;
use alchemy::{get_platform_endianess, get_network_endianess}; use alchemy::{get_platform_endianess, get_network_endianess};

View File

@ -8,15 +8,6 @@
extern crate scribe;
extern crate weave;
extern crate spellbook;
#[cfg(feature="sigils")]
extern crate sigils;
#[macro_use] #[macro_use]
mod macros; mod macros;
@ -28,15 +19,15 @@ mod transmutable;
pub use crate::byte_sized::ByteSized; pub use self::byte_sized::ByteSized;
pub use crate::byte_sized::{U8_BYTES, U16_BYTES, U32_BYTES, U64_BYTES, USIZE_BYTES}; pub use self::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 self::byte_sized::{I8_BYTES, I16_BYTES, I32_BYTES, I64_BYTES, ISIZE_BYTES};
pub use crate::byte_sized::{F32_BYTES, F64_BYTES}; pub use self::byte_sized::{F32_BYTES, F64_BYTES};
pub use crate::byte_sized::get_byte_size_of_string; pub use self::byte_sized::get_byte_size_of_string;
pub use crate::conversion_error::ConversionError; pub use self::conversion_error::ConversionError;
pub use crate::converter::Converter; pub use self::converter::Converter;
pub use crate::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian}; pub use self::endian::{BigEndian, LittleEndian, PlatformEndian, NetworkEndian};
pub use crate::endian::Endianess; pub use self::endian::Endianess;
pub use crate::endian::{network_to_platform_order, platform_to_network_order}; pub use self::endian::{network_to_platform_order, platform_to_network_order};
pub use crate::endian::{get_network_endianess, get_platform_endianess}; pub use self::endian::{get_network_endianess, get_platform_endianess};
pub use crate::transmutable::Transmutable; pub use self::transmutable::Transmutable;

View File

@ -1,3 +1,5 @@
use weave::attempt;
use spellbook::components::Array; use spellbook::components::Array;
#[cfg(feature="convert_sigils")] #[cfg(feature="convert_sigils")]