solution to exercise 04_01

This commit is contained in:
David Doblas Jiménez 2024-07-01 16:15:42 +02:00
parent 4a4fc2ea0d
commit ebe07acd1e
2 changed files with 17 additions and 1 deletions

View File

@ -1,6 +1,6 @@
fn intro() -> &'static str { fn intro() -> &'static str {
// TODO: fix me 👇 // TODO: fix me 👇
"I'm ready to __!" "I'm ready to learn about traits!"
} }
#[cfg(test)] #[cfg(test)]

View File

@ -3,6 +3,22 @@
// //
// Then implement the trait for `u32` and `i32`. // Then implement the trait for `u32` and `i32`.
pub trait IsEven {
fn is_even(self) -> bool;
}
impl IsEven for u32 {
fn is_even(self) -> bool {
self % 2 == 0
}
}
impl IsEven for i32 {
fn is_even(self) -> bool {
self % 2 == 0
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;