Expand description
§use-fs
Composable filesystem-adjacent primitives for RustUse.
§Experimental
use-fs is experimental while the workspace remains below 0.3.0. Expect API
adjustments as the first wave settles.
§Example
#[cfg(feature = "full")]
use use_fs::*;
#[cfg(feature = "full")]
{
assert_eq!(path_kind("docs/guide.md"), PathKind::Relative);
assert_eq!(normalize_extension(".TAR.GZ"), "tar.gz");
assert_eq!(sanitize_file_name("report?.txt"), "report-.txt");
}§Scope
- feature-gated access to the focused
use-fscrates - direct reexports for path, file-name, extension, directory, and stem helpers
- one dependency for callers that want the full first-wave workspace
§Non-goals
- adding filesystem I/O APIs
- hiding crate boundaries behind heavy abstraction
- replacing
std::pathorstd::fs
§License
Licensed under either of the following, at your option:
- Apache License, Version 2.0
- MIT license
Re-exports§
pub use use_dir as dir;pub use use_extension as extension;pub use use_file_name as file_name;pub use use_file_stem as file_stem;pub use use_path as path;
Structs§
- Directory
Path - A string-backed directory path.
- File
Extension - A string-backed file extension.
- File
Name - A string-backed file name.
- File
Stem - A string-backed file stem.
- Path
Parts - A lexical view of a path-like input.
Enums§
- Path
Kind - Classifies a path-like input using a small lexical model.
- Path
Separator - Describes which separator styles appear in a path-like input.
Functions§
- append_
to_ file_ stem - Appends a suffix to the file stem while preserving the original extension suffix.
- compound_
extension - Extracts a supported compound extension from a file name or path-like input.
- detect_
path_ separator - Detects which path separator style appears in the input.
- dir_
name - Extracts the most relevant directory segment from a path-like input.
- ensure_
dir_ trailing_ separator - Ensures a trailing
/for non-empty directory paths. - ensure_
trailing_ separator - Ensures a trailing
/for non-empty input. - extension
- Extracts the last simple extension from a file name or path-like input.
- extension_
from_ path - Extracts the final simple extension from a path-like input.
- extension_
lowercase - Extracts the last simple extension and lowercases it.
- file_
name - Extracts the final file-name segment from a path-like input.
- file_
name_ from_ path - Extracts the final file-name segment from a path-like input.
- file_
stem - Extracts the simple file stem from a file name or path-like input.
- file_
stem_ without_ compound_ extension - Extracts the file stem while removing a supported compound extension when present.
- has_
extension - Returns
truewhen a path-like input has a simple extension. - has_
extension_ eq - Returns
truewhen the last simple extension matches the given candidate. - has_
file_ stem - Returns
truewhen the input has a recoverable file stem. - has_
reserved_ file_ name - Returns
truewhen the extracted file name is a reserved Windows name. - is_
absolute_ path - Returns
truewhen the input begins with a recognized absolute prefix. - is_
compound_ extension - Returns
truewhen the input ends with a supported compound extension. - is_
current_ dir - Returns
truewhen the input refers to the current directory. - is_
empty_ path - Returns
truewhen the input is empty. - is_
hidden_ file_ name - Returns
truewhen the extracted file name is a hidden dotfile. - is_
parent_ dir - Returns
truewhen the input refers to the parent directory. - is_
relative_ path - Returns
truewhen the input is non-empty and not absolute. - is_
root_ dir - Returns
truewhen the input is a recognized root directory. - is_
safe_ file_ name - Returns
truewhen the extracted file name avoids reserved names and unsafe characters. - join_
path_ parts - Joins path parts with
/while preserving a leading absolute prefix when present. - normalize_
dir_ path - Normalizes directory separators to
/and removes trailing separators unless the input is a root. - normalize_
extension - Normalizes an extension by removing leading dots and lowercasing it.
- normalize_
file_ name - Normalizes a file name by trimming surrounding whitespace.
- normalize_
path_ separators - Normalizes path separators to
/. - parent_
path - Extracts the lexical parent path when one is present.
- path_
depth - Returns the lexical depth of a directory path.
- path_
kind - Returns the lexical kind for a path-like input.
- path_
parts - Returns lexical directory, file-name, and extension parts.
- prepend_
to_ file_ stem - Prepends a prefix to the file stem while preserving the original extension suffix.
- relative_
to_ dir - Computes a lexical relative path when
baseis a prefix ofpath. - remove_
unsafe_ file_ name_ chars - Removes unsafe characters and control characters from a file name.
- replace_
unsafe_ file_ name_ chars - Replaces unsafe characters and control characters with a safe replacement.
- sanitize_
file_ name - Sanitizes a file name by trimming, replacing unsafe characters, and disarming reserved names.
- slug_
file_ stem_ basic - Converts a file stem into a conservative ASCII slug.
- split_
path_ parts - Splits a path-like input into normalized non-empty segments.
- starts_
with_ dir - Returns
truewhen the input starts with the given directory on segment boundaries. - strip_
dir_ trailing_ separator - Removes trailing separators while preserving roots.
- trim_
trailing_ separator - Removes trailing separators while preserving recognized roots.
- with_
extension - Replaces the last simple extension or appends one when missing.
- with_
file_ stem - Replaces the file stem while preserving the original extension suffix.
- without_
extension - Removes the last simple extension while preserving directory segments.