| Crates.io | cross-path |
| lib.rs | cross-path |
| version | 0.0.1 |
| created_at | 2026-01-20 17:52:30.361062+00 |
| updated_at | 2026-01-20 17:52:30.361062+00 |
| description | Advanced cross-platform path handling library for Windows/Linux path conversion |
| homepage | |
| repository | https://github.com/houseme/cross-path |
| max_upload_size | |
| id | 2057107 |
| size | 107,552 |
English | 简体中文
Advanced cross-platform path handling library for perfect Windows and Unix path conversion.
[dependencies]
cross_path = "0.0.1"
use cross_path::CrossPath;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Windows to Unix conversion
let cp = CrossPath::new(r"C:\Users\John\file.txt")?;
println!("Unix path: {}", cp.to_unix()?); // /mnt/c/Users/John/file.txt
// Unix to Windows conversion
let cp = CrossPath::new("/home/john/file.txt")?;
println!("Windows path: {}", cp.to_windows()?); // C:\home\john\file.txt
// Direct conversion
let unix_path = r"C:\Users\test".to_unix_path()?;
println!("Direct conversion: {}", unix_path);
Ok(())
}
use cross_path::{CrossPath, PathConfig, PathStyle};
let config = PathConfig {
style: PathStyle::Auto,
preserve_encoding: true,
security_check: true,
drive_mappings: vec![
("C:".to_string(), "/mnt/c".to_string()),
("D:".to_string(), "/mnt/data".to_string()),
],
normalize: true,
};
let cp = CrossPath::with_config(r"D:\Data\file.txt", config) ?;
println!("Converted: {}", cp.to_unix()?); // /mnt/data/Data/file.txt
use cross_path::security::PathSecurityChecker;
let checker = PathSecurityChecker::new();
let path = std::path::Path::new("../../etc/passwd");
match checker.check(path) {
Ok(_) => println ! ("Path is safe"),
Err(e) => println ! ("Security warning: {}", e),
}
// Sanitize dangerous paths
let safe_path = PathSecurityChecker::sanitize_path("file<>.txt");
println!("Safe path: {}", safe_path); // file__.txt
use cross_path::unicode::UnicodeHandler;
// Detect encoding
let bytes = b"C:\\Users\\\x93\x65\x88\x97\\file.txt";
let encoding = UnicodeHandler::detect_encoding(bytes);
println!("Detected encoding: {}", encoding.name());
// Convert to UTF-8
let utf8_string = UnicodeHandler::convert_to_utf8(bytes) ?;
println!("UTF-8 string: {}", utf8_string);
For detailed API documentation, run:
cargo doc --open
# Run all tests
cargo test
# Run specific tests
cargo test --test conversion
# Run benchmarks
cargo bench
MIT OR Apache-2.0 (LICENSE-MIT, LICENSE-APACHE)