Skip to content

Commit

Permalink
Add example for single variant record let structuring
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri authored and lpil committed Sep 17, 2024
1 parent c6328f6 commit bedc73e
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ pub type Fish {
Jellyfish(name: String, jiggly: Bool)
}

pub type IceCream {
IceCream(flavour: String)
}

pub fn main() {
let lucy = Starfish("Lucy", "Pink")
let favourite_ice_cream = IceCream("strawberry")

case lucy {
Starfish(_, favourite_color) -> io.debug(favourite_color)
Jellyfish(name, ..) -> io.debug(name)
}

// if the custom type has a single variant you can
// destructure it using `let` instead of a case expression!
let IceCream(flavour) = favourite_ice_cream
io.debug(flavour)
}

0 comments on commit bedc73e

Please sign in to comment.