Skip to content

Instantly share code, notes, and snippets.

@michaelsproul
Created December 22, 2014 05:54
Show Gist options
  • Save michaelsproul/d094e6954567246cc0e3 to your computer and use it in GitHub Desktop.
Save michaelsproul/d094e6954567246cc0e3 to your computer and use it in GitHub Desktop.
Rust Closure Variables
fn stuff() {
// Split the path into its components, and make each component a path.
let simple_map = |comp: &str| -> Pattern {
Pattern::simple_pattern(comp)
};
let glob_map = |comp: &str| -> Pattern {
Pattern::glob_pattern(comp)
};
let map_fn = match prelude {
SimpleInclude | SimpleExclude => simple_map,
GlobInclude | GlobExclude => glob_map
};
let components: Vec<Pattern> = path.split('/').map(map_fn).collect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment