From 6e581440bfc9dc1da318088dc1dd492461183e1a Mon Sep 17 00:00:00 2001 From: LukeMathWalker <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 14 May 2024 15:54:26 +0200 Subject: [PATCH] Explain. --- .../04_traits/09_assoc_vs_generic/src/lib.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exercises/04_traits/09_assoc_vs_generic/src/lib.rs b/exercises/04_traits/09_assoc_vs_generic/src/lib.rs index 3cefb78..84f3e7b 100644 --- a/exercises/04_traits/09_assoc_vs_generic/src/lib.rs +++ b/exercises/04_traits/09_assoc_vs_generic/src/lib.rs @@ -1,5 +1,17 @@ -// TODO: Define a new trait, `Power`, that has a method `power` that raises `self` to the power of `n`. -// The trait definition and its implementations should be enough to get the tests to compile and pass. +// TODO: Define a new trait, `Power`, that has a method `power` that raises `self` +// to the power of `n`. +// The trait definition and its implementations should be enough to get +// the tests to compile and pass. +// +// Recommendation: you may be tempted to write a generic implementation to handle +// all cases at once. However, this is fairly complicated and requires the use of +// additional crates (i.e. `num-traits`). +// Even then, it might be preferable to use a simple macro instead to avoid +// the complexity of a highly generic implementation. Check out the +// "Little book of Rust macros" (https://veykril.github.io/tlborm/) if you're +// interested in learning more about it. +// You don't have to though: it's perfectly okay to write three separate +// implementations manually. Venture further only if you're curious. #[cfg(test)] mod tests {