Releases: hyfdev/sugar_path
Releases · hyfdev/sugar_path
Release list
sugar_path-v3.0.0
Breaking redesign of the public path APIs for borrowing, explicit cwd, and owned-buffer reuse (#40). Public docs and continuous CI allocation gates were aligned with that surface (#42). Performance baselines landed first as PR #41.
Added
- Add
try_absolutizeandtry_relativefor callers that handle ambient current-directory errors. - Add
relative_withfor relative calculation against an explicit externally managed cwd. - Add strict, fallible strict, and explicitly lossy slash conversion for borrowed paths and consuming
PathBufvalues. - Add consuming
PathBufnormalization through the sealedSugarPathBufextension trait.
Changed
- Seal
SugarPathas an extension-method namespace implemented directly forPathandstr; owned standard types and string wrappers continue to use it through deref method lookup. - Change
relativeto returnCow<Path>directly, borrowing a canonical descendant suffix when possible; callers requiringPathBufuseCow::into_owned. - Follow Node-style host-native normalization by preserving one trailing separator on non-root paths and preserving Windows drive-letter spelling while retaining case-insensitive drive comparison.
- Keep relative output independent from normalization's trailing-separator preservation: equal paths return an empty path and target trailing separators are removed.
- Change
to_slashto the ergonomic strict conversion that panics for invalid Unicode, and move the non-replacing fallible contract totry_to_slash. - Change
absolutize_withandrelative_withto accept borrowed or owned cwd values directly without requiring callers to constructCow; an ownedPathBufmay transfer its allocation. - Preserve full non-UTF-8
PathandOsStrbehavior for path operations; only conversion to Unicode chooses strict, fallible, or lossy policy.
Fixed
- Preserve complete drive, UNC, verbatim UNC, and device roots when calculating Windows relative paths, including invalid-wide fallback inputs.
- Preserve unresolved Windows drive-relative paths when an explicit cwd belongs to another drive instead of consulting ambient state or fabricating a rooted path.
- Preserve literal
/characters inside Windows verbatim components, keep or insert the minimal.\needed to prevent a normal component from becoming a prefix during normalization, and return the normalized target when a component cannot be represented as a standalone native relative path.
Performance
- Avoid current-directory access for inputs whose result is cwd-independent.
- Avoid result allocation for canonical native descendant
relativecalls on Unix and Windows. - Reuse owned cwd, normalized
PathBuf, and valid-Unicode slash-conversion buffers where possible. - Use separator-aware Windows comparisons, inline component storage,
memchr, and target-specific common-prefix scanning for Rolldown-shaped paths.
Migration
- Append
.into_owned()torelative(base)only where the former ownedPathBufresult is still required. - For known-UTF-8 owned text, replace
relative(base).to_slash_lossy().into_owned()withrelative(base).into_owned().into_slash(); otherwise select the strict fallible or explicitly lossy conversion that matches the caller's encoding policy. - Replace
to_slash().unwrap()withto_slash()when valid UTF-8 is an invariant, and usetry_to_slash()when invalid encoding is recoverable. - Pass cwd directly to
absolutize_withandrelative_with; do not wrap it inCow::BorrowedorCow::Owned.
v2.0.1
Fixed
- support wasm platform
Other
- polish README.md
v2.0.0
v1.2.1
v1.0.0
What's Changed
Breaking changes compared to 0.0.12
SugarPathBuftrait is removed.AsPathtrait is removed. Its functionalities is merged intoSugarPath.- The return type of methods of
SugarPathis changed toPathBuffromCow<Path>.
Refined Functionalities
- SugarPath::as_path makes it easy to convert
T: Deref<Target = str>toPathand allows to you methods ofSugarPathon&strorStringdirectly.
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