3

I'm trying to understand an implementation of a binary tree in Rust and I can't wrap my head around some scoping magic in the locate_mut function:

match {anchor} {
    &mut Some(ref mut node) if key != node.value.key() => {
        anchor = if key < node.value.key() {
            &mut node.left
        } else {
            &mut node.right
        }
    },
    other @ &mut Some(_) |
    other @ &mut None => return other
}
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Sergey
  • 1,166
  • 14
  • 27
  • 5
    [Related blog post: "stuff the identity function does"](https://bluss.github.io/rust/fun/2015/10/11/stuff-the-identity-function-does/) (the linked list example is pretty similar to the binary tree code of yours). I hope Shepmaster answers your question ^_^ – Lukas Kalbertodt May 07 '17 at 11:38
  • @LukasKalbertodt or that Matthieu M and oli_obk - ker have already answered it ;-) – Shepmaster May 07 '17 at 13:11

0 Answers0