fork(2) download
  1. use std::cmp::Ordering::*;
  2.  
  3. type Link<T> = Option<Box<Node<T>>>;
  4.  
  5. #[derive(Debug)]
  6. struct Node<T: Ord> {
  7. value: T,
  8. right: Link<T>,
  9. left: Link<T>,
  10. }
  11.  
  12. impl<T: Ord> Node<T> {
  13. fn new(value: T) -> Self {
  14. Node {
  15. value: value,
  16. right: None,
  17. left: None
  18. }
  19. }
  20. fn add(&mut self, value: T) {
  21. let mut next;
  22. match self.value.cmp(&value) {
  23. Less => {
  24. next = &mut self.left;
  25. },
  26. Greater => {
  27. next = &mut self.right;
  28. },
  29. Equal => {panic!()}
  30. }
  31. if next.is_some() {
  32. //src/lib.rs:32:13: 32:17 error: cannot move out of borrowed content
  33. //src/lib.rs:32 next.unwrap().add(value);
  34. // ^~~~
  35. next.unwrap().add(value);
  36. }
  37. else {
  38. *next = Some(Box::new(Node::new(value)));
  39. }
  40. }
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
error: main function not found
error: aborting due to previous error
stdout
Standard output is empty