Add solution sheet8

This commit is contained in:
Lukas Kalbertodt
2017-01-04 13:56:02 +01:00
parent 61db78f64b
commit 9f2347a0be
2 changed files with 364 additions and 0 deletions

19
aufgaben/sheet8/sol1/times.rs Executable file
View File

@ -0,0 +1,19 @@
fn main() {
3.times(|i| {
println!("Ferris ate {} cookies", i);
});
}
trait ChristmasExt<T> {
fn times<F: FnMut(T)>(&self, f: F);
}
// We would somehow implement this for all integer types, but this is just
// a proof of concept, so one impl for `i32` is fine.
impl ChristmasExt<i32> for i32 {
fn times<F: FnMut(i32)>(&self, mut f: F) {
for i in 0..*self {
f(i);
}
}
}