Struct support
No due date
75% complete
Support structs and enums in a more friendly way. The end vision for this is being able to do something like this:
struct Counter {
count: u64,
max: u64
}
impl Counter {
contract! {
fn increment(&mut self) {
invariant {
assert!(self.count <= self.max, "counter max exceeded");
}
body {
…
Support structs and enums in a more friendly way. The end vision for this is being able to do something like this:
struct Counter {
count: u64,
max: u64
}
impl Counter {
contract! {
fn increment(&mut self) {
invariant {
assert!(self.count <= self.max, "counter max exceeded");
}
body {
self.count += 1;
}
post {
assert!(self.count >= 0, "counter overflowed");
}
}
fn decrement(&mut self) {
invariant {
assert!(self.count <= self.max, "counter max exceeded");
}
pre {
assert!(self.count > 0, "attempted to decrement empty counter");
}
body {
self.count += 1;
}
}
}
}
Note the following points:
- We can use the
contract!
macro for any number offn
declarations, thus only needing one. - We can use
self
and variants.