Expand description
§mi-simple-io
Small synchronous IO utilities for common file and terminal workflows.
use mi_simple_io::{read_file, remove, write_file};
let file = std::env::temp_dir().join("mi_simple_io_doctest.txt");
write_file(&file, "hello")?;
assert_eq!(read_file(&file)?, "hello");
remove(&file)?;Structs§
Functions§
- append_
file - Append text to a file, creating it when missing.
- clear_
dir - Remove all directory contents while keeping the directory itself.
- confirm
- Ask a yes/no question and return the selected answer.
- copy_
file - Copy a file and return the number of bytes copied.
- create_
dir - Create a directory and any missing parents.
- current_
dir - Return the current working directory.
- exists
- Return whether a path exists.
- file_
extension - Return the lowercase file extension as UTF-8 lossy text, or an empty string.
- file_
size - Return file size in bytes.
- file_
stats - Read a text file and return basic statistics.
- file_
stem - Return the file stem as UTF-8 lossy text, or an empty string.
- is_dir
- Return whether a path is a directory.
- is_file
- Return whether a path is a regular file.
- move_
file - Move or rename a file or directory.
- parse_
confirmation - Parse confirmation text using a default for empty or unknown input.
- read_
all_ lines - Read all lines from a file.
- read_
bytes - Read a file into bytes.
- read_
file - Read a UTF-8 text file into a string.
- read_
first_ lines - Read the first
nlines from a file. - read_
input - Read a trimmed line from standard input after printing a prompt.
- read_
last_ lines - Read the last
nlines from a file. - read_
lines - Read a file as a line iterator, preserving line read errors.
- remove
- Remove a file or directory tree.
- safe_
write - Write text via a sibling temporary file before replacing the destination.
- temp_
dir - Return the system temporary directory.
- write_
file - Write text to a file, replacing existing content.
- write_
or_ append - Write text when the file is missing, otherwise append it.