Releases: hyf0/sugar_path
Releases · hyf0/sugar_path
v1.0.0
What's Changed
Breaking changes compared to 0.0.12
SugarPathBuf
trait is removed.AsPath
trait is removed. Its functionalities is merged intoSugarPath
.- The return type of methods of
SugarPath
is changed toPathBuf
fromCow<Path>
.
Refined Functionalities
- SugarPath::as_path makes it easy to convert
T: Deref<Target = str>
toPath
and allows to you methods ofSugarPath
on&str
orString
directly.
use std::path::Path;
use sugar_path::SugarPath;
assert_eq!("foo".as_path().join("bar"), Path::new("foo/bar"));
assert_eq!("foo/./bar/../baz".normalize(), "foo/baz".as_path());
- SugarPath::to_slash/SugarPath::to_slash_lossy allows you to convert the path to the string with consistent slash separator on all platforms.
use sugar_path::SugarPath;
#[cfg(target_family = "unix")]
let p = "./hello/world".as_path();
#[cfg(target_family = "windows")]
let p = ".\\hello\\world".as_path();
assert_eq!(p.to_slash().unwrap(), "./hello/world");
assert_eq!(p.to_slash_lossy(), "./hello/world");
- SugarPath::normalize allows you normalize given path by dropping unnecessary
.
or..
segments.
use std::path::Path;
use sugar_path::SugarPath;
assert_eq!("foo/./bar/../baz".normalize(), "foo/baz".as_path());
- SugarPath::relative allows you to get the relative path from the given path to the target path.
use sugar_path::SugarPath;
assert_eq!("/base".relative("/base/project"), "..".as_path());
assert_eq!("/base".relative("/var/lib"), "../../base".as_path());
- SugarPath::absolutize is a shortcut of SugarPath::absolutize_with with passing
std::env::current_dir().unwrap()
as the base path.
use sugar_path::SugarPath;
let cwd = std::env::current_dir().unwrap();
assert_eq!("hello/world".absolutize(), cwd.join("hello").join("world"));
- SugarPath::absolutize_with allows you to absolutize the given path with the base path.
use sugar_path::SugarPath;
#[cfg(target_family = "unix")]
{
assert_eq!("./world".absolutize_with("/hello"), "/hello/world".as_path());
assert_eq!("../world".absolutize_with("/hello"), "/world".as_path());
}
#[cfg(target_family = "windows")]
{
assert_eq!(".\\world".absolutize_with("C:\\hello"), "C:\\hello\\world".as_path());
assert_eq!("..\\world".absolutize_with("C:\\hello"), "C:\\world".as_path());
}
- For more details, please refer to the SugarPath.
Refined Documentation
I rewrite the documents of using SugarPath
. It should be more straightforward for users to understand what SugarPath
does.
See https://docs.rs/sugar_path/latest/sugar_path/ for more details.
New Contributors
- @hyf0 made their first contribution in #1
- @shulandmimi made their first contribution in #5
Full Changelog: https://github.com/hyf0/sugar_path/commits/v1.0.0