Add solutions for sheet6

This commit is contained in:
Lukas Kalbertodt
2016-12-05 17:57:47 +01:00
parent 509cdd453d
commit 08a4b2fccc
7 changed files with 197 additions and 0 deletions

27
aufgaben/sheet6/sol3/swagger.rs Executable file
View File

@ -0,0 +1,27 @@
use std::fmt;
struct Swagger<T>(pub T);
impl<T: fmt::Display> fmt::Display for Swagger<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "yolo {} swag", self.0)
}
}
trait SwaggerExt: Sized {
fn with_swag(self) -> Swagger<Self>;
}
impl<T> SwaggerExt for T {
fn with_swag(self) -> Swagger<Self> {
Swagger(self)
}
}
fn main() {
let pi = 3.14;
println!("{}", pi);
println!("{}", Swagger(pi));
println!("{}", pi.with_swag());
}