two functions, two ways to write them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| }) | |
| } |
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
Obviously the 1nth. (You decide how the index works.)