Skip to content

Evaluate switching to std::path::absolute() once that method is stabilized #30

Closed
@simu

Description

@simu

Context

Currently, we're using a custom to_lexical_absolute() function (copied from https://internals.rust-lang.org/t/path-to-lexical-absolute/14940) to transform relative paths to their absolute counterparts without following symlinks, cf.

reclass-rs/src/lib.rs

Lines 47 to 69 in 1780735

/// Converts `p` to an absolute path, but doesn't resolve symlinks. The function does normalize the
/// path by resolving any `.` and `..` components which are present.
///
/// Copied from https://internals.rust-lang.org/t/path-to-lexical-absolute/14940.
fn to_lexical_absolute(p: &Path) -> Result<PathBuf> {
let mut absolute = if p.is_absolute() {
PathBuf::new()
} else {
std::env::current_dir()?
};
for component in p.components() {
match component {
Component::CurDir => { /* do nothing for `.` components */ }
Component::ParentDir => {
// pop the last element that we added for `..` components
absolute.pop();
}
// just push the component for any other component
component => absolute.push(component.as_os_str()),
}
}
Ok(absolute)
}

There's discussions around stabilizing std::path::absolute() which is currently available as an unstable feature in nightly Rust. We should check if we can replace our custom to_lexical_absolute() with this method once it's stabilized.

Alternatives

Do nothing and keep maintaining a function that could be replaced by a stdlib method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions