Unpack a modules resource

How does one access the value inside a modules own resource from a pass by value argument like the following?

resource x {
value: u64
}

public func(input: Self.x): u64 {
let result: u64;
//How would you get the value inside the resource?
}

It seems to be possible if the argument is a mutable reference but not when the resource is passed by value??

The Move IR syntax for this in the inverse of Pack:

public func(input: Self.X): u64 {
  let value: u64;
  X { value } = move(input);
  return value;
}

Also: you might want to try out the new Move source language! The syntax is much nicer than the old (IR) (e.g., no need to declare variables up-front or type move() and copy() anymore), and the error messages are very helpful in situations like this.

1 Like