Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Rust library to operate files easily and quickly

NotificationsYou must be signed in to change notification settings

dhchenx/rsfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Rust library to operate files or web pages easily and quickly

Functions

Thersfile library include simplified operation functions for commonly used I/O, text files, csv files and web crawlers.

Examples

File Operations

use rsfile::*;fnmain(){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 modelin 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);}

Web Page Operations

use rsfile::*;fnmain(){// 1. get HTML page information (including html string, title, meta, raw text, etc.)let page=fetch_html("https://www.rust-lang.org/");for kin page.keys(){println!("{}\t{:?}",k,page.get(k));};//2.  get HTML page from a local path and obtain its HTML stringlet page=read_html_file("data/webpage.html");let html_opt=page.get("html");}

Standard IO Operations

use rsfile::*;fnmain(){// read a linelet line=input_line();// read a line after a messagelet line=input_line_with_msg("Please input a line:");// read binarylet content =read_binary("data/test.txt");// write a text file for one timewrite_text_once("data/test2.txt","Hello, Rust!");// write a list of linesletmut lines:Vec<&str>=Vec::new();    lines.push("a");    lines.push("b");append_text("data/test2.txt",lines);}

Other available functions are:

text files

  • read_text()
  • write_text()
  • read_lines()
  • append_text()
  • write_text_once()
  • write_lines()

csv files

  • read_csv()
  • read_csv_text()
  • read_csv_with_error()
  • write_csv_with_error()

HTML pages

  • fetch_html()
  • read_html_file()
  • read_html_string()

Input/Output

  • input()
  • input_line()
  • input_line_with_msg()
  • print()
  • read_binary()

More example codes can be foundhere.

License

MIT

About

A Rust library to operate files easily and quickly

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp