use std::cmp::Ordering::*;
type Link<T> = Option<Box<Node<T>>>;
#[derive(Debug)]
struct Node<T: Ord> {
value: T,
right: Link<T>,
left: Link<T>,
}
impl<T: Ord> Node<T> {
fn new(value: T) -> Self {
Node {
value: value,
right: None,
left: None
}
}
fn add(&mut self, value: T) {
let mut next;
match self.value.cmp(&value) {
Less => {
next = &mut self.left;
},
Greater => {
next = &mut self.right;
},
Equal => {panic!()}
}
if next.is_some() {
//src/lib.rs:32:13: 32:17 error: cannot move out of borrowed content
//src/lib.rs:32 next.unwrap().add(value);
// ^~~~
next.unwrap().add(value);
}
else {
*next = Some(Box::new(Node::new(value)));
}
}
}
dXNlIHN0ZDo6Y21wOjpPcmRlcmluZzo6KjsKCnR5cGUgTGluazxUPiA9IE9wdGlvbjxCb3g8Tm9kZTxUPj4+OwoKI1tkZXJpdmUoRGVidWcpXQpzdHJ1Y3QgTm9kZTxUOiBPcmQ+IHsKICAgIHZhbHVlOiBULAogICAgcmlnaHQ6IExpbms8VD4sCiAgICBsZWZ0OiBMaW5rPFQ+LAp9CgppbXBsPFQ6IE9yZD4gTm9kZTxUPiB7CiAgICBmbiBuZXcodmFsdWU6IFQpIC0+IFNlbGYgewogICAgICAgIE5vZGUgewogICAgICAgICAgICB2YWx1ZTogdmFsdWUsCiAgICAgICAgICAgIHJpZ2h0OiBOb25lLAogICAgICAgICAgICBsZWZ0OiBOb25lCiAgICAgICAgfQogICAgfQogICAgZm4gYWRkKCZtdXQgc2VsZiwgdmFsdWU6IFQpIHsKICAgICAgICBsZXQgbXV0IG5leHQ7CiAgICAgICAgbWF0Y2ggc2VsZi52YWx1ZS5jbXAoJnZhbHVlKSB7CiAgICAgICAgICAgIExlc3MgPT4gewogICAgICAgICAgICAgICAgbmV4dCA9ICZtdXQgc2VsZi5sZWZ0OwogICAgICAgICAgICB9LAogICAgICAgICAgICBHcmVhdGVyID0+IHsKICAgICAgICAgICAgICAgIG5leHQgPSAmbXV0IHNlbGYucmlnaHQ7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIEVxdWFsID0+IHtwYW5pYyEoKX0KICAgICAgICB9CiAgICAgICAgaWYgbmV4dC5pc19zb21lKCkgewogICAgICAgICAgICAvL3NyYy9saWIucnM6MzI6MTM6IDMyOjE3IGVycm9yOiBjYW5ub3QgbW92ZSBvdXQgb2YgYm9ycm93ZWQgY29udGVudAogICAgICAgICAgICAvL3NyYy9saWIucnM6MzIgICAgICAgICAgICAgbmV4dC51bndyYXAoKS5hZGQodmFsdWUpOwogICAgICAgICAgICAvLyAgICAgICAgICAgICAgICAgICAgICAgICAgXn5+fgogICAgICAgICAgICBuZXh0LnVud3JhcCgpLmFkZCh2YWx1ZSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICAqbmV4dCA9IFNvbWUoQm94OjpuZXcoTm9kZTo6bmV3KHZhbHVlKSkpOwogICAgICAgIH0KICAgIH0KfQo=