X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/ff92eaa5332ba1ac1efab2d6be3a227774fb5946..de20ea2de7cb19c2c379fcd61279e13da9c8193d:/src/part03.rs?ds=inline diff --git a/src/part03.rs b/src/part03.rs index 25f9386..b81bbc3 100644 --- a/src/part03.rs +++ b/src/part03.rs @@ -99,9 +99,10 @@ pub fn main() { min.print(); /*@*/ } -// **Exercise 03.1**: Define a trait `Print` to write a generic version of -// `SomethingOrNothing::print`. -// Implement that trait for `i32`, and change `main` above to use the new generic `print` function. +// **Exercise 03.1**: The goal is to write a generic version of `SomethingOrNothing::print`. +// To this end, define a trait `Print` that provides (simple) generic printing, and implement +// that trait for `i32`. Then define `SomethingOrNothing::print2` to use that trait, and change +// `main` above to use the new generic `print2` function. // I will again provide a skeleton for this solution. It also shows how to attach bounds to generic // implementations (just compare it to the `impl` block from the previous exercise). // You can read this as "For all types `T` satisfying the `Print` trait, I provide an implementation @@ -114,6 +115,9 @@ pub fn main() { pub trait Print { /* Add things here */ } +impl Print for i32 { + /* Add things here */ +} impl SomethingOrNothing { fn print2(self) { unimplemented!()