Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.94 KB | None | 0 0
  1. #[derive(Debug, Clone)]
  2. pub enum ChunkContent<'a> {
  3.    Text(&'a str),
  4.     Tokens(Box<Vec<Token>>),
  5.     Block(Box<Branch<'a>>),
  6. }
  7.  
  8. #[derive(Debug, Clone)]
  9. pub struct Chunk<'a> {
  10.     pub content: ChunkContent<'a>,
  11. }
  12.  
  13. #[derive(Debug, Clone)]
  14. pub struct Branch<'a> {
  15.     pub content: Vec<Chunk<'a>>,
  16. }
  17.  
  18. //
  19. // other place in other module
  20. //
  21.  
  22. pub fn tokenize_branch_mutate(branch: &mut Branch<'a>) {
  23.      for mut chunk in branch.content.iter() {
  24.          match chunk.content
  25.             ChunkContent::Text(t) => {
  26.  
  27.                 // !!!
  28.                 // Cannot assign immutable field 'chunk.content'
  29.  
  30.                 chunk.content = ChunkContent::Tokens(Box::new(Self::tokenize(t)));
  31.             },
  32.  
  33.             ChunkContent::Block(ref mut b) => { // Cannot borrow immutable private field '... Block).0' as mutable
  34.                 Self::tokenize_branch_mutate(b);
  35.             },
  36.  
  37.             _ => continue,
  38.         }
  39.      }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement