Skip to main content

Crate pathkit

Crate pathkit 

Source
Expand description

Owned filesystem paths with synchronous and optional asynchronous file operations.

Path retains platform-native path data and dereferences to std::path::Path. Lexical transformations return new paths; SyncFsOps performs blocking filesystem operations without updating the stored path. The path! macro supports direct path expressions and formatted string literals. Directory entries expose owned paths through PathEntry.

§Getting started

use pathkit::path;

let root = path!("project");
let config = &root / "config" / "app.json";
assert_eq!(config, root.join("config").join("app.json"));
assert_eq!(root, path!("project"));

§Features

No optional features are enabled by default. Serde support and synchronous operations are always available.

  • async-fs-ops enables AsyncFsOps and AsyncPathEntry, adding Tokio and async-trait. Async filesystem operations require a Tokio runtime with blocking-task support. Dropping a future does not roll back completed changes or necessarily stop submitted I/O.
  • sea-orm adds SeaORM model-field and value conversions. Paths are stored as strings; writing a non-Unicode path replaces invalid Unicode with the replacement character.
  • all enables both optional features.
  • full enables all.

Enable a feature with cargo add pathkit --features async-fs-ops, replacing the feature name as needed. Serde delegates to std::path::PathBuf; serialization fails for native paths that are not valid UTF-8, rather than replacing invalid Unicode.

§Platform support

Path parsing, joining, and ordering follow the standard library’s platform-specific semantics. Unix permission modes, ownership operations, and special-file checks are available only on Unix. Hard links are available on supported platforms; symbolic-link creation is Unix-only. Filesystem permissions, link behavior, and rename restrictions depend on the operating system and filesystem.

§Examples

The following example creates and removes only a temporary directory. Write and remove operations elsewhere can overwrite or delete existing data.

use pathkit::{
    SyncFsOps,
    path,
};

let directory = tempfile::tempdir()?;
let file = path!(directory.path()) / "message.txt";
file.write_sync(b"Hello!")?;
assert_eq!(file.read_to_string_sync()?, "Hello!");
assert_eq!(file.get_file_size_sync()?, 6);

§See also

Macros§

path
Creates an owned Path from a path expression or formatted string literal.

Structs§

Path
An owned filesystem path with path transformations and filesystem extension traits.
PathEntry
A directory entry with owned Path access and native file-name and metadata queries.

Traits§

SyncFsOps
Blocking filesystem operations for paths.