Crates.io | rsfile |
lib.rs | rsfile |
version | 0.1.2 |
source | src |
created_at | 2022-01-31 09:07:18.190824 |
updated_at | 2022-01-31 19:57:02.125406 |
description | A Rust library to operate files or web pages easily and quickly |
homepage | |
repository | https://github.com/dhchenx/rsfile/ |
max_upload_size | |
id | 524474 |
size | 42,895 |
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.
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::read_csv_simple("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 list_model=rsfile::read_csv("data/test.csv");
let flag=rsfile::write_csv("data/test1.csv",list_model);
println!("{}",flag);
}
use rsfile::*;
fn main(){
// 1. get HTML page information (including html string, title, meta, raw text, etc.)
let page=fetch_html("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=read_html_file("data/webpage.html");
let html_opt=page.get("html");
}
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