Unowned
. For example:
transaction foo(LightSwitch@Unowned s) {
s.turnOff(); // COMPILE ERROR: can't change state of s through an unowned reference
}
Shared
. These references can be used to change the state of the referenced object, but invoking transactions that can only be called in some states requires a runtime check. For example:
transaction test1(LightSwitch@Shared s) {
s.turnOn(); // COMPILE ERROR: turnOn requires that s be Off, but s is Shared.
}
In the above situation, the programmer might need to check the state dynamically with if...in
.
When a Shared
reference is needed, an Owned
suffices as long as the reference is NOT to an asset. For example, an Owned
reference can be passed as an argument to a transaction that expects a Shared
reference to a non-resource object. However, the caller is left with a Shared
reference.
When an Unowned
reference is needed, any reference suffices, and the caller is left with their original kind of reference.