pub fn rebase<T: AsRef<Path>>(
file_path: T,
new_path: T,
old_path: Option<T>,
) -> Option<PathBuf>Expand description
Rebase the file path relative to a new base path, optionally removing a common prefix.
§Arguments
file_path- The original file path to rebase.new_path- The new base path to which the file path will be rebased.old_path- An optional common prefix to remove from the file path before rebasing.
§Returns
Returns the rebased file path if successful, or None if any error occurs.
§Examples
Rebase a file path to a new base path without removing any common prefix:
use std::path::PathBuf;
let file_path = "/home/user/documents/file.txt";
let new_path = "/mnt/storage";
let rebased_path = proper_path_tools::path::rebase( file_path, new_path, None ).unwrap();
assert_eq!( rebased_path, PathBuf::from( "/mnt/storage/home/user/documents/file.txt" ) );Rebase a file path to a new base path after removing a common prefix:
use std::path::PathBuf;
let file_path = "/home/user/documents/file.txt";
let new_path = "/mnt/storage";
let old_path = "/home/user";
let rebased_path = proper_path_tools::path::rebase( file_path, new_path, Some( old_path ) ).unwrap();
assert_eq!( rebased_path, PathBuf::from( "/mnt/storage/documents/file.txt" ) );