How to use RefCell properly

Hello,

I have a doubt about my code.
I have a code like that:
Where: var_decl_attribute: Rc<RefCell<VarDeclAttribute<'a>>>

    {
        let var_decl = var_decl_attribute.borrow_mut();
        let mut lexer_code_gen = var_decl.lexer_code_gen.borrow_mut();
       //code...
    }

    let var_size_synthetized = self.var_type.parse(Rc::clone(&var_decl_attribute))?.unwrap();
    
   {
        let var_decl = var_decl_attribute.borrow_mut();
        let mut lexer_code_gen = var_decl.lexer_code_gen.borrow_mut();
        //code...
   }

As you can see, there are 2 block, because inside the method call: self.var_type.parse, I need also the var_decl_attribute.borrow_mut.

My code works correctly, but, is using { } block to stop borrowing before calling self.var_type.parse() good design?

Thanks!

It is perfectly fine.

If you want, you can also do it without blocks by dropping var_decl and lexer_code_gen.

2 Likes

Thanks a lot!