The bool
strategy
The bool
strategy can be applied to fields of type bool
.
fields {
#[sharding(bool)]
pub field: bool,
}
Tokens.
VerusSync creates a fresh token type, tok
,
named State::field
where State
is the name of the VerusSync system and field
is the name of the field.
The token type tok
implements the
UniqueSimpleToken
trait.
Relationship between global field value and the token.
When field
is false
, this corresponds to no token existing, while
when field
is true
, this corresponds to a token existing.
The token doesn’t contain any additional data.
Having multiple such tokens at the same time is an impossible state.
Manipulation of the field
Quick Reference
In the following table, b: bool
.
Command | Meaning in transition | Exchange Fn Parameter |
---|---|---|
init field = b; |
init field = b; |
Output Option<tok> |
remove field -= true; |
require field == true; update field = false; |
Input tok |
have field >= true; |
require field == true; |
Input &tok |
add field += true; |
assert field == false; update field = true; |
Output tok |
remove field -= (b); |
require (b ==> field);
update field = field && !b; |
Input Option<tok> |
have field >= (b); |
require (b ==> field); |
Input &Option<tok> |
add field += (b); |
assert !(field && b);
update field = field || b; |
Output Option<tok> |
Initializing the field
Initializing the field is done with the usual init
statement (as it for all strategies).
init field = b;
The instance-init function will return a token of type Option<tok>
,
related as follows:
value of b: bool |
value of optional token Option<tok> |
---|---|
false |
None |
true |
Some(tok) where tok.value() == v |
Adding a token
To write an operation that creates a token,
equivalently,
updating the field’s value from false
to true
, write, inside any transition!
operation:
add field += true;
This operation has an inherent safety condition that the prior value of field
is false
.
The resulting token exchange function will return a token of type tok
.
Removing a token
To write an operation that removes a token,
equivalently,
updating the field’s value from true
to false
, write, inside any transition!
operation:
remove field -= true;
The resulting exchange function will consume a tok
token
as a parameter.
Checking the value of the token
To check the value of the token without removing it,
write, inside any transition!
, readonly!
or property!
operation:
have field >= true;
The resulting exchange function will accept an immutable reference
&tok
(that is, it takes the token as input but does not consume it).
Operations that manipulate optional tokens
You can also write versions of the above operations that operate on optional tokens.
The operations below are equivalent to the above versions whenever b == true
,
and they are all no-ops when b == false
.
To create an Option<tok>
:
add field += (b);
To consume an Option<tok>
:
remove field -= (b);
To check the value of an &Option<tok>
:
have field >= (b);
The value of b
is related to the value of
Option<tok>
as they are for initialization.
Example
TODO