Skip to content

Collecting into a PathBuf from Iterator<Item=Component> is hard. #41866

Closed
@Mark-Simulacrum

Description

@Mark-Simulacrum

See discussion here: #41531.

To summarize, the following should work, but currently doesn't. It's likely that implementing impl<P: AsRef<OsStr>> FromIterator<P> for PathBuf would solve this, but I haven't tested.

use std::path::{PathBuf, Path};

fn main() {
    let path = Path::new("a/b/c/d");
    println!("{:?}", path.components().filter(|c| c.as_os_str() != "b").collect::<PathBuf>());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-acceptedCategory: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions