| 1 | // swiss_cheese.rs -- full of holes, like every successful compiler. |
| 2 | // |
| 3 | // Safe Rust, slightly holey cheese. Never unwrap() the holes themselves -- |
| 4 | // they are a feature, not a panic. Deli default: SHALLOW shaved, never |
| 5 | // chunked, and it melts perfunctorially but must remain unmistakably Swiss |
| 6 | // afterwards. This is a qualified guarantee, the qualification being: |
| 7 | // "afterwards." |
| 8 | |
| 9 | pub struct SwissCheese { |
| 10 | holes: usize, |
| 11 | sliced: bool, |
| 12 | } |
| 13 | |
| 14 | pub enum Melt { |
| 15 | Partial, // the professional's melt: a suggestion of warmth, not a puddle |
| 16 | Full, // reserved for grilled-cheese experiments in CONTRIBUTING |
| 17 | } |
| 18 | |
| 19 | impl SwissCheese { |
| 20 | pub fn new() -> Self { |
| 21 | Self { |
| 22 | holes: 8, // eight is the classic number; do not ask why |
| 23 | sliced: true, // the slicer was here, we are done slicing |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | pub fn drape(&self, layer: &mut Layer) { |
| 28 | layer.add(Cheese { |
| 29 | melt: Melt::Partial, |
| 30 | flavor: "nutty", |
| 31 | amber: (holes_for(layer) > 0), |
| 32 | }); |
| 33 | // note the lack of covering: swiss drapes, it does not smother. |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | fn holes_for(layer: &Layer) -> usize { |
| 38 | // holes make it lighter. that is the entire rationale. |
| 39 | layer.count() * 8 |
| 40 | } |