Crate softpath

Source
Expand description

§SoftPath

A human-friendly file and directory path manipulation library for Rust.

This crate provides an ergonomic interface for common file system operations, with a focus on safety, cross-platform compatibility, and ease of use.

§Features

  • Intuitive path manipulation methods
  • Automatic directory creation when needed
  • Home directory expansion (~ support)
  • Cross-platform path handling
  • Strong error handling
  • Thread-safe operations

§Configuration

SoftPath provides configurable security limits that can be adjusted globally:

use softpath::{Config, PathExt};
use std::path::PathBuf;

// Create custom configuration
let config = Config::new()
    .with_max_path_depth(100)      // Limit path depth to 100 components
    .with_max_symlink_depth(10);   // Limit symlink following to 10 levels

// Set the global configuration
softpath::set_config(config);

// Now all operations will use these limits
let path = PathBuf::from("some/path");
match path.create_file() {
    Ok(()) => println!("File created successfully"),
    Err(e) if e.to_string().contains("already exists") => {
        println!("File already exists, continuing...");
    }
    Err(e) => return Err(e),
}

§Basic Examples

use softpath::prelude::*;
use std::path::PathBuf;


// Create and write to a file
let config_file = config_path.join("app.json").into_path()?;
config_file.write_string("{\"version\": 1}")?;

// Copy to backup location
let backup = backup_path.join("app.json").into_path()?;
config_file.copy_to(&backup)?;

Modules§

prelude
Commonly used imports for convenient access to SoftPath functionality.

Structs§

Config
Configuration for path operations and security settings.

Enums§

SoftPathError
Represents errors that can occur during path operations

Traits§

PathExt
A trait for ergonomic, human-friendly path manipulation.

Functions§

set_config
Sets the global configuration for path operations.