simple-fs
simple-fs is a crate that provides a set of convenient and common file APIs built on std::fs, walkdir, and globset.
Concept
simple-fs operates under the assumption that paths which are not utf8 are not visible to the API, which simplifies many of the path-related APIs.
The two constructs that follow this assumption are:
-
SPath, which ensures that the contained path is a valid UTF-8 path and includes a file name. -
SFile, which carries the same guarantees asSPathbut also checks if the fileis_file(), confirming the file's existence at the time of theSFileconstruction.
By establishing these rules, APIs such as .file_name(), .file_stem(), and .to_str() are much simpler, as they all return &str.
The crate also includes other convenient, common APIs:
read_to_string, which reports the file path if not found.get_buf_reader, which also reports the file path if not found or in case of an error.load_jsonandsave_jsonwith thewith-jsonfeature.load_tomlandsave_tomlwith thewith-tomlfeature.iter_files(dir, include_globs: &[&str], exclude_globs: &[&str]) -> Result<impl Iter...>
For more control, it is recommended to use std::fs, walkdir, globset, and other crates directly.
Cargo Features
with-json- Forload_json,save_json,save_json_prettywith-toml- Forload_toml,save_tomlbin-nums- Forsave_be_f64,save_le_f64,load_be_f64, ...
This is a very early implementation, with more to come.
Happy coding!