код
                  
                  
                  struct Container {
                  
                  
                      cache: RefCell<HashSet<Type>>
                  
                  
                  }
                  
                  
                  
                  
                  
                  impl Container {
                  
                  
                      fn get(&self, val: Type) -> &Type {
                  
                  
                          let mut set = self.cache.borrow_mut();
                  
                  
                          set.get_or_insert(val)
                  
                  
                      }
                  
                  
                  }
                  
                  
                  
                  
                  
                  Строка с get_or_insert фейлится с тем, что я ссылаюсь на локальный set
                  
                  
                  error[E0515]: cannot return value referencing local variable `set`
                  
                  
                    --> src/ast/producer.rs:44:9
                  
                  
                     |
                  
                  
                  44 |         set.get(val).unwrap()
                  
                  
                     |         ------------^^^^^^^^^
                  
                  
                     |         |
                  
                  
                     |         returns a value referencing data owned by the current function
                  
                  
                     |         `set` is borrowed here
                  
                  
                  
                  
                  
                  Как убедить его, что у меня ссылка на self и ничего не стухнет?
                  
                  
                
У тебя немутабельная ссылка на селф, как минимум
Обсуждают сегодня