Files

597 B

03 — Struktury, Enumy i Pattern Matching

Zakres

  • Definiowanie struct oraz metod w blokach impl
  • enum z danymi (algebraic data types)
  • match, Option<T>

Zadania (src/lib.rs)

  1. Rectangle::area(&self) -> u32 oraz Rectangle::can_hold(&self, other: &Rectangle) -> bool.
  2. Shape::area(&self) -> f64 dla enuma Shape (Circle(f64) oraz Rect { width: f64, height: f64 }).
  3. safe_divide(a: f64, b: f64) -> Option<f64> — None przy dzieleniu przez 0.0, w przeciwnym razie Some(a / b).

Uruchomienie testów

make test PKG=core03-structs-enums