| Crates.io | simple-fs |
| lib.rs | simple-fs |
| version | 0.10.0 |
| created_at | 2023-12-27 19:25:29.818297+00 |
| updated_at | 2026-01-19 18:42:13.760011+00 |
| description | Simple and convenient API for File System access |
| homepage | https://github.com/jeremychone/rust-simple-fs |
| repository | https://github.com/jeremychone/rust-simple-fs |
| max_upload_size | |
| id | 1081826 |
| size | 208,960 |
simple-fs is a crate that provides a set of convenient and common file APIs built on std::fs, walkdir, and globset.
simple-fs operates under the assumption that paths that are not utf8 are not visible to the API, simplifying many of the path-related APIs.
The main construct of simple-fs is the SPath structure, which contains a Utf8PathBuf and ensures the following:
/ (no \), and redundant // or /./ are collapsed to a single ./.\\?\ on Windows.By applying the above rules, path/file APIs can be drastically simplified, and SPath offers many Path functions, with &str as the return type.
This crate also offers a simple and scalable way to list or iterate on files, given a glob:
iter_files(dir, include_globs: Option<&[&str]>, list_options: Option<ListOptions>) -> Result<impl Iterator<Item = SPath>>list_files(dir, include_globs: Option<&[&str]>, list_options: Option<ListOptions>) -> Result<Vec<SPath>>ensure_dir(dir_path) makes sure all the directory paths are created.ensure_file_dir(file_path) makes sure the file directory exists.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.For more control, it is recommended to use std::fs, walkdir, globset, and other crates directly.
This is a very early implementation, with more to come.
Happy coding!
| Feature | Functions Included |
|---|---|
with-json |
load_json, save_json, save_json_pretty |
with-toml |
load_toml, save_toml |
bin-nums |
save_be_f64, load_be_f64, save_le_f64, ... |
full |
All the above. |
| default | None of the above. See below. |
0.10.0 No more SFile (SPath for all, SFile was a left-over from early design. Did not provide real value, just code/API duplication)0.9.0-alpha.x Same API (for now), but new optimized list_files(...) (hence the large version jump)0.8.x Removed 'target/' and 'node_modules/' from the default excludes (too presumptive)0.7.x SMeta.size is now u64 (changed from i64), new APIs0.6.x
..std_path.. naming./ and removes redundant // and /./).SPath/SFile.! Deprecated '.to_str()', now '.as_str()'! .diff(..) - Now takes AsRef Utf8Path, returns Option+ Add collapse, into_collapsed, is_collapsed, try_collapse! .clean(..) is replaced by .collapse()+ list/iter files/dirs - Added support for negative glob patterns in include_globs (convenience).! API CHANGE - Now all default to Utf8Path (from camino crate). Use std_path...() for the standard path.^ sfile/spath - Added is_absolute/is_relative passthrough.0.5.0
0.4.0
notify 8 (should not have any API changes)SPath::from(&str/&String,String) (no need for try_from)0.3.1 from 0.3.0
list/iter files.
* was traversing into subfolders /, which was not the intended behavior.0.3.1, it uses the glob literal_separator = true, so it won't descend further.*.rs to list direct descendants and **/*.rs for nested files.dir given in the list; otherwise, set ListOptions.relative_glob = true to make it relative.0.3.x from 0.2.x
0.2.0 from 0.1.x