fast_io
A simple and fast file I/O for the rust programming language
This library enables you to read and write &str as well as types implementing the copy trait.
How to use it
Add it to your dependencies (Cargo.toml)
[dependecies]
fast_io = 0.1.0
Include it and use it in your code (src/main.rs)
extern crate fast_io;
use fast_io::IOExt;
use std::fs::File;
fn main() {
let file_path = "some_file.txt";
let a : i32 = -42;
let b : f64 = 42.42;
let c : u16 = 15;
let d : Point = Point { x: 42.0, y: 42.0 };
let e : &str = "Hello World!";
let mut f = File::create(file_path).unwrap();
f.write_copy(&a);
f.write_copy(&b);
f.write_copy(&c);
f.write_copy(&d);
f.write_str("Hello World!");
let mut f = File::open(file_path).unwrap();
let a2 : i32 = f.read_copy();
let b2 : f64 = f.read_copy();
let c2 : u16 = f.read_copy();
let d2 : Point = f.read_copy();
let e2 = &f.read_str();
assert_eq!(a, a2);
assert_eq!(b, b2);
assert_eq!(c, c2);
assert_eq!(d, d2);
assert_eq!(e, e2);
}
#[derive(Debug)]
#[derive(Copy)]
struct Point {
x: f64,
y: f64
}
impl Clone for Point {
fn clone(&self) -> Self {
*self
}
}
impl std::cmp::PartialEq for Point {
fn eq(&self, other: &Self) -> bool {
self == other
}
}