0

I have the following code:

((&self.items).get(&self.lastIndex)).unwrap().val1 = "hello";
((&self.items).get(&self.lastIndex)).unwrap().val2 = "world";

Map of ink storage. How can I unwrap the struct from KV once and modify all values at once? Like so:

/// not rust syntax
((&self.items).get(&self.lastIndex))
.unwrap()->{
  this.val1 = "";
  this.val2 = "";
}
Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77
weg
  • 11
  • 2
  • You can't `get(...).value = ...`. `get()` returns a shared, immutable reference. – Chayim Friedman May 21 '22 at 23:03
  • 1
    What is the problem with assigning the result to a variable and then mutating it? Like `let item = self.items.get_mut(&self.last_index).unwrap(); item.val1 = "hello"; item.val2 = "world";`? – Chayim Friedman May 21 '22 at 23:04

0 Answers0