reading libstd::trie of rust

After reading libstd::bool I chose libstd::trie because the special thing about rust is pointer management. The code is at least readable although I had to go back to the language manual to see the meaning of ~.

The ~ shows an owned box. An owned box is a chunk of memory which is freed whenever the owner is out of scope.

enum Child<T> {
   Internal(~TrieNode<T>),  // what is this ~ ?  OK.  It's an owned box.
   External(uint, T),
   Nothing
}

For me, it was a bit strange to see that Mutable trait requires clear method. Intuitively, a mutable thing should have a method called update or something.

impl<T> Mutable for TrieMap<T> {
    /// Clear the map, removing all values.
    #[inline]
    fn clear(&mut self) {
        self.root = TrieNode::new();
        self.length = 0;
    }
}

I am in the midst of reading insert operation. I like the match expression on the right hand side of =. I do not understand why swap appears here. Also, the chunk function is still a mystery for me.

fn insert<T>(count: &mut uint, child: &mut Child<T>, key: uint, value: T,
             idx: uint) -> Option<T> {
    let mut tmp = Nothing;
    let ret;
    swap(&mut tmp, child); // why not just tmp = child ?

    *child = match tmp {
      External(stored_key, stored_value) => {
          if stored_key == key {
              ret = Some(stored_value);
              External(stored_key, value) //value changed
          } else {
              // conflict - split the node
              let mut new = ~TrieNode::new();
              insert(&mut new.count,
                     &mut new.children[chunk(stored_key, idx)],
                     stored_key, stored_value, idx + 1);
              ret = insert(&mut new.count, &mut new.children[chunk(key, idx)],
                           key, value, idx + 1); // recursion here.
              Internal(new)
          }
      }
      Internal(x) => { // well, OK, internals are internal nodes.
        let mut x = x;
        ret = insert(&mut x.count, &mut x.children[chunk(key, idx)], key,
                     value, idx + 1);
        Internal(x)
      }
      Nothing => {
        *count += 1;
        ret = None;
        External(key, value)
      }
    };
    return ret;
}