initial commit

This commit is contained in:
2025-02-19 10:34:15 +05:30
commit b9cb4c290a
355 changed files with 18626 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,39 @@
enum Shape {
Circle { radius: f64 },
Square { border: f64 },
Rectangle { width: f64, height: f64 },
}
impl Shape {
// TODO: Implement the `radius` method using
// either an `if let` or a `let/else`.
pub fn radius(&self) -> f64 {
todo!()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_circle() {
let _ = Shape::Circle { radius: 1.0 }.radius();
}
#[test]
#[should_panic]
fn test_square() {
let _ = Shape::Square { border: 1.0 }.radius();
}
#[test]
#[should_panic]
fn test_rectangle() {
let _ = Shape::Rectangle {
width: 1.0,
height: 2.0,
}
.radius();
}
}