Skip to content

Instantly share code, notes, and snippets.

@Geal
Geal / gist:540ddd745045e7335c0d
Created January 14, 2015 12:47
create a closure depending on a parameter
fn prod<'a,'b>(a:uint) -> Box<FnMut(&'b[u8]) -> &'b[u8] +'a> {
box move |&: input: &'b[u8]| -> &'b[u8] {
input.slice_from(a)
}
}
fn main() {
let mut a = prod(2);
println!("a1: {}", a("abcdefgh".as_bytes()));
// -> a1: [99, 100, 101, 102, 103, 104]