extern crate serde;
#[macro_use]
extern crate serde_derive;
pub mod disp {
use std::fmt;
pub fn print<T>(text: T) where T: fmt::Display {
println!("{}", text);
return;
}
pub fn newline() {
println!("");
return;
}
pub fn print_debug<T>(data: T) where T: fmt::Debug {
println!("{:?}", data);
return;
}
}
pub mod range {
pub fn range(x: u32, y: u32) -> Vec<u32> {
let mut iterator = x;
let mut list = Vec::new();
list.push(iterator);
while iterator != y {
iterator += 1;
list.push(iterator);
}
return list;
}
}
pub mod arg {
use std::env;
pub fn get_args() -> Vec<String> {
let args = env::args().collect();
return args;
}
}
pub mod conv {
use std::string::String;
pub fn b_str(str: &str) -> String {
let no_borrow: String = str.to_string();
return no_borrow;
}
}
pub mod stringutil {
pub fn get_char_pos(string: String, char_loc: usize) -> char {
let char_vec: Vec<char> = string.chars().collect();
return char_vec[char_loc];
}
}
pub mod appinfo {
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct AppInfo {
pub name: &'static str,
pub author: &'static str,
pub repository: &'static str,
pub crate_link: &'static str,
}
impl AppInfo {
pub fn new() -> AppInfo {
let appinfo: AppInfo = AppInfo {name: "", author: "", repository: "", crate_link: ""};
return appinfo;
}
}
}
pub mod point {
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct Point {
pub x: i32,
pub y: i32,
}
impl Point {
pub fn new() -> Point {
let point: Point = Point {x: 0, y: 0};
return point;
}
}
}
pub mod coordinate {
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct Coordinate {
pub x: i32,
pub y: i32,
pub z: i32,
}
impl Coordinate {
pub fn new() -> Coordinate {
let coordinate: Coordinate = Coordinate {x: 0, y: 0, z: 0};
return coordinate;
}
}
}
pub mod shape {
pub mod quadrilateral {
use point::Point;
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct Quadrilateral {
pub corner: [Point; 4],
}
impl Quadrilateral {
pub fn new() -> Quadrilateral {
let quadrilateral: Quadrilateral = Quadrilateral {corner: [Point {x: 0, y: 0}; 4]};
return quadrilateral;
}
}
}
pub mod hexahedron {
use coordinate::Coordinate;
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct Hexahedron {
pub corner: [Coordinate; 8],
}
impl Hexahedron {
pub fn new() -> Hexahedron {
let hexahedron: Hexahedron = Hexahedron {corner: [Coordinate {x: 0, y: 0, z: 0}; 8]};
return hexahedron;
}
}
}
}
pub mod error {
use std::process;
use disp;
use conv::b_str;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Error {
pub errormessage: String,
pub exitcode: i32,
pub exit: bool,
}
pub fn const_error(errormessage: &'static str, exitcode: i32) -> Error {
let error = Error {errormessage: b_str(errormessage), exitcode: exitcode, exit: true};
return error;
}
pub fn const_error_noexit(errormessage: &'static str) -> Error {
let error = Error {errormessage: b_str(errormessage), exitcode: 1, exit: false};
return error;
}
pub fn error(error: Error) {
disp::print([b_str("Error: "), error.errormessage, b_str("\n")].concat());
if error.exit {
process::exit(error.exitcode);
}
}
}
#[cfg(test)]
mod tests {
use ::range;
use ::error;
#[test]
fn range() {
let testvec = range::range(0, 4);
println!("{:?}", testvec);
}
#[test]
fn error() {
let error = error::const_error_noexit("This is a sample error, beep beep.");
error::error(error);
}
}