A Rust library to operate files or web pages easily and quickly
The rsfile
library include simplified operation functions for commonly used I/O, text files, csv files and web crawlers.
```rust use rsfile::*; fn main(){ use rsfile; // read a csv file and load a list of HashMap models // where you can get value by key. let result=rsfile::readcsvsimple("data/test.csv"); for model in result{ println!("RECORD: {:?}",model); } // save a csv file by using a list of HashMap models // where you can get value by key. let listmodel=rsfile::readcsv("data/test.csv"); let flag=rsfile::writecsv("data/test1.csv",listmodel); println!("{}",flag);
} ```
```rust
use rsfile::*;
fn main(){ // 1. get HTML page information (including html string, title, meta, raw text, etc.) let page=fetchhtml("https://www.rust-lang.org/"); for k in page.keys(){ println!("{}\t{:?}",k,page.get(k)); }; //2. get HTML page from a local path and obtain its HTML string let page=readhtmlfile("data/webpage.html"); let htmlopt=page.get("html"); } ```
rust
use rsfile::*;
fn main(){
// read a line
let line=input_line();
// read a line after a message
let line=input_line_with_msg("Please input a line:");
// read binary
let content = read_binary("data/test.txt");
// write a text file for one time
write_text_once("data/test2.txt","Hello, Rust!");
// write a list of lines
let mut lines:Vec<&str>=Vec::new();
lines.push("a");
lines.push("b");
append_text("data/test2.txt",lines);
}
Other available functions are:
More example codes can be found here.
MIT