03 — Struktury, Enumy i Pattern Matching
Zakres
- Definiowanie
struct oraz metod w blokach impl
enum z danymi (algebraic data types)
match, Option<T>, Result<T, E>
Zadania (src/lib.rs)
Rectangle::area(&self) -> u32 oraz Rectangle::can_hold(&self, other: &Rectangle) -> bool.
Shape::area(&self) -> f64 dla enuma Shape (Circle(f64) oraz Rect { width: f64, height: f64 }).
safe_divide(a: f64, b: f64) -> Option<f64> — zwróć None przy dzieleniu przez 0.0, w przeciwnym razie Some(a / b).
Uruchomienie testów