Path Calculate
This is a library help you to calculate with Path or PathBuf, such as get absolute path, get the relate root or the relative path between two pathes, get the '~'(home_dir) if it exist.
This is based on path_absolutize library, I've use as_absolute_path replace the row absolutize, because it do not support '~' which is use recently, at least in UNIX System.
The following examples show the usage about this crate.
Examples
There are some methods you can use.
home_dir
Get the current user's HOME if it exist in your env, or it return an error(I'm lazy, so just put this method in the Calculate trait).
extern crate path_calculate;
use Path;
use *;
let p = new;
if let Ok = p.home_dir
as_absolute_path
This is almost like a shadow of the absolutize in path-absolutize, I only add ~($HOME) support in the method(Unix or Windnows).
extern crate path_calculate;
use Path;
use *;
// If u have $HOME, test `~` support
let p = new;
if let Ok = p.home_dir
let p2 = new;
assert_eq!;
relative_root_with
Sometimes I would use the relative root of pathes, it return an absolutize relative_root path.
Behold, in Windows, it can not calculate the relative_root on different disks(C:\, D:\,,,), when you try to use this method it return an ioerror such as io::ErrorKind::InvalidInput.
extern crate path_calculate;
use Path;
use *;
let p1 = new;
let p2 = new;
let relative_root = p1.relative_root_with;
assert_eq!
extern crate path_calculate;
use ErrorKind;
use Path;
use *;
// Pass Test when in Unix
if cfg!
related_to
This method is used to calculate the dst_path's relative path from the src_path.
extern crate path_calculate;
use Path;
use *;
// $HOME="/home/chao"
let dst_path = new;
let src_path = new;
assert_eq!;
add_path
Band path_a with path_b(Path_b should be a relative path, can not contain ~, too).
It return an abs path, I think u must want this.
extern crate path_calculate;
use Path;
use *;
let base_path = new;
let extra_path = new;
assert_eq!;
let empty_path = new;
assert_eq!;