Skip to content

std::path::Path::starts_with documentation unclear #24882

Closed
@0X1A

Description

@0X1A

The current documentation for std::path::Path::starts_with does not specify that it uses components as base. For example as described in the current documentation I expected to be able to use characters as base to find hidden files/directories as such:

fn is_dot(dir: &PathBuf) -> bool {
    if dir.starts_with(".") {
        return true;
    } else {
        return false
    }
}

fn main() {
    let path = PathBuf::from("/home/user/.dotfile");
    let rel_path = path.relative_from("/home/user").unwrap();
    println!("{}", path.display());
    println!("{}", rel_path.display());
    if is_dot(&PathBuf::from(rel_path)) {
        println!("{} is dot", rel_path.display());
    }
}

As described in the documentation I expected is_dot(&PathBuf::from(rel_path)) to be evaluated as true when it does not

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions