wsd is an intuitive crate delivers What Simply Defined.
Intutive File Class
Just a convenient wrapper to rust File, check the return value quickly as we did with C API, don't need to check the Result, and unwrap() etc.
Methods
File::new()
File::open()
File::read()
File::write()
File::seek()
File::length()
File::close()
File::error()
Open flags
O_CREATE
O_TRUNCATE
O_RW
O_READ
O_WRITE
O_APPEND
Seek flags
SEEK_SET
SEEK_CUR
SEEK_END
Example
using wsd::fs::*;
fn test() -> i32 {
let mut f = File::new();
if f.open("test.txt", O_CREATE | O_RW) != 0 {
println!("Error: {}", f.error());
return -1;
}
let data = "Hello World!";
let n = f.write(data);
if n < 0 {
}
f.rewind();
let mut buf = [0; 4096];
let n = f.read(&mut buf);
if n > 0 {
}
let off = f.length();
if off > 0 {
}
f.seek(256, SEEK_SET);
f.write("more data");
f.close();
return 0;
}