619 B
619 B
03 — Struktury, Enumy i Pattern Matching
Zakres
- Definiowanie
structoraz metod w blokachimpl enumz danymi (algebraic data types)match,Option<T>,Result<T, E>
Zadania (src/lib.rs)
Rectangle::area(&self) -> u32orazRectangle::can_hold(&self, other: &Rectangle) -> bool.Shape::area(&self) -> f64dla enumaShape(Circle(f64)orazRect { width: f64, height: f64 }).safe_divide(a: f64, b: f64) -> Option<f64>— zwróćNoneprzy dzieleniu przez0.0, w przeciwnym razieSome(a / b).
Uruchomienie testów
make test PKG=ex03-structs-enums