>>103308392
use std::mem::swap;
#[derive(Debug)]
pub struct Tree<T> {
value: T,
left: Option<Link<T>>,
right: Option<Link<T>>,
}
type Link<T> = Box<Tree<T>>;
impl<T> Tree<T> {
pub fn invert(&mut self) {
swap(&mut self.left, &mut self.right);
if let Some(left) = &mut self.left {
left.invert();
}
if let Some(right) = &mut self.right {
right.invert();
}
}
}
Isn't that all you need? I didn't test it or think about it for more than a minute.