Skip to content

Instantly share code, notes, and snippets.

Created February 7, 2018 20:07
Embed
What would you like to do?
two functions, two ways to write them
fn name_to_path(name: &str) -> PathBuf {
let mut iter = name.split("::");
iter.next().unwrap(); // get rid of the initial name, since it's the crate name
let mut path = PathBuf::new();
iter.for_each(|component| {
path.push(component);
});
path
}
fn name_to_path(name: &str) -> PathBuf {
name.split("::").skip(1).fold(PathBuf::new(), |mut path, component| {
path.push(component);
path
})
}
@artiegold
Copy link

Obviously the 1nth. (You decide how the index works.)

@Kerollmops
Copy link

Does this work ?

fn name_to_path(name: &str) -> PathBuf {
    name.split("::").skip(1).collect()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment