Skip to main content

quick_start/
quick_start.rs

1use mi_simple_io::{
2    append_file, create_dir, file_stats, read_all_lines, read_file, remove, write_file, TempFile,
3};
4
5fn main() -> std::io::Result<()> {
6    let root = std::env::temp_dir().join("mi_simple_io_quick_start");
7    if root.exists() {
8        remove(&root)?;
9    }
10    create_dir(&root)?;
11
12    let log = root.join("hello.txt");
13    write_file(&log, "Hello, Rust!\n")?;
14    append_file(&log, "Simple IO makes common tasks short.\n")?;
15    // Print file path
16    println!("File path: {}", log.display());
17    println!("{}", read_file(&log)?);
18    for line in read_all_lines(&log)? {
19        println!("line: {line}");
20    }
21
22    let temp = TempFile::with_content("quick_start", "temporary data")?;
23    println!("temp: {}", temp.path().display());
24
25    let stats = file_stats(&log)?;
26    println!(
27        "size={} lines={} words={} chars={}",
28        stats.size, stats.lines, stats.words, stats.chars
29    );
30
31    // remove(root)?;
32    Ok(())
33}