100 exercises to learn Rust

This commit is contained in:
LukeMathWalker
2024-05-12 22:21:03 +02:00
commit 5edebf6cf2
309 changed files with 13173 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
[package]
name = "assoc_vs_generic"
version = "0.1.0"
edition = "2021"

View File

@@ -0,0 +1,25 @@
// 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.
#[cfg(test)]
mod tests {
use super::Power;
#[test]
fn test_power_u16() {
let x: u32 = 2_u32.power(3u16);
assert_eq!(x, 8);
}
#[test]
fn test_power_u32() {
let x: u32 = 2_u32.power(3u32);
assert_eq!(x, 8);
}
#[test]
fn test_power_ref_u32() {
let x: u32 = 2_u32.power(&3u32);
assert_eq!(x, 8);
}
}