Borrow-checking with friends

enum D3 { One, Two, Three }
impl D3 {
    fn peek(self: &D3, name: &str) {
        println!("{} sees that it's {:?}.", name, self);

Our main character, named Max, has a d3.

fn main() {
    print!("Hi, I'm Max. ");
    let mut die = D3::Two;

Max can rolls his die:

die = D3::One;

Max invites Alice and Bob over for a game of dice. The die is on the table and everyone can see what it's showing.

'table: loop {
    let bob = ¨
    die.peek("Everyone"); // same thing
    break 'table; // that's enough peeking for now

It's Alice's turn, she picks up the die and rolls.

'alices_turn: loop {
    let alice = &mut die;
    *alice = D3::Three;
    break 'alices_turn;

It lands on the table and now everyone sees what Alice rolled.


Full code.