Advertisement
NLinker

Why does it compile?

Sep 23rd, 2021
1,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.94 KB | None | 0 0
  1. // TODO make an MRE for it
  2.  
  3. fn build_tree(
  4.     rep: &[u8],
  5.     i: &mut usize,
  6.     parent: Option<&String>,
  7.     tree: &mut ViewTree<String, Custom>,
  8. ) -> Option<()> {
  9.     let acceptable = b"( ,)";
  10.     let mut is_gathering = true;
  11.     let mut buf = String::with_capacity(3);
  12.     let mut node = parent;
  13.     while *i < rep.len() {
  14.         let x = rep[*i];
  15.         if is_gathering {
  16.             if x.is_ascii_alphanumeric() {
  17.                 buf.push(x as char);
  18.                 *i += 1;
  19.             } else if acceptable.contains(&x) {
  20.                 tree.add_child_node(buf.clone(), parent, Custom {
  21.                     state: State::Pending,
  22.                     name: format!("{}_payload", buf)
  23.                 });
  24.                 node = Some(&buf);
  25.                 buf.clear();
  26.                 is_gathering = false;
  27.             } else {
  28.                 return None;
  29.             }
  30.         } else  {
  31.  
  32.         }
  33.     }
  34.     Some(())
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement