100 exercises to learn Rust

This commit is contained in:
LukeMathWalker committed 2024-05-12 22:47:45 +02:00
commit 5edebf6cf2
309 files changed
+13173

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
[package]
name = "trait_"
version = "0.1.0"
edition = "2021"
+23
View File
@@ -0,0 +1,23 @@
// Define a trait named `IsEven` that has a method `is_even` that returns a `true` if `self` is
// even, otherwise `false`.
//
// Then implement the trait for `u32` and `i32`.
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_u32_is_even() {
assert!(42.is_even());
assert!(!43.is_even());
}
#[test]
fn test_i32_is_even() {
assert!(42.is_even());
assert!(!43.is_even());
assert!(0.is_even());
assert!(!(-1).is_even());
}
}