История изменений
Исправление Deleted, (текущая версия) :
После пропускания через rustfmt
#[derive(PartialEq)]
struct Node<'a> {
val: &'a str,
l: Option<Box<Node<'a>>>,
r: Option<Box<Node<'a>>>,
}
impl<'a> Node<'a> {
pub fn insert(&mut self, new_val: &'a str) {
if self.val == new_val {
return;
}
let target_node = if new_val < self.val {
&mut self.l
} else {
&mut self.r
};
match target_node {
&mut Some(ref mut subnode) => subnode.insert(new_val),
&mut None => {
let new_node = Node {
val: new_val,
l: None,
r: None,
};
let boxed_node = Some(Box::new(new_node));
*target_node = boxed_node;
}
}
}
}
Исходная версия Deleted, :
После пропускания через rustfmt
#[derive(PartialEq)]
struct Node<'a> {
val: &'a str,
l: Option<Box<Node<'a>>>,
r: Option<Box<Node<'a>>>,
}
impl<'a> Node<'a> {
pub fn insert(&mut self, new_val: &'a str) {
if self.val == new_val {
return;
}
let target_node = if new_val < self.val {
&mut self.l
} else {
&mut self.r
};
match target_node {
&mut Some(ref mut subnode) => subnode.insert(new_val),
&mut None => {
let new_node = Node {
val: new_val,
l: None,
r: None,
};
let boxed_node = Some(Box::new(new_node));
*target_node = boxed_node;
}
}
}
}