Skip to content

Commit 103588b

Browse files
committed
polish the README
1 parent 094df2e commit 103588b

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ You can include any number of each flavor. Multiple conditions of the same flavo
9595
// precondition, `self.is_initialized && !self.is_locked`.
9696
requires: self.is_initialized,
9797
requires: !self.is_locked,
98-
// The next one is an invariant
98+
// The next one is an invariant.
9999
maintains: self.len() <= self.capacity(),
100100
)]
101101
fn push(&mut self, value: T) { /* ... */ }
@@ -114,29 +114,29 @@ fn get_positive_value() -> i32 { /* ... */ }
114114

115115
If the name `output` collides with an existing identifier, you can choose a different name for it in two ways:
116116

117-
**1. Contract-Wide Name**: Use the `binds` parameter to set a new name for the return value across all postconditions in the contract.
117+
**1. Contract-Wide Binding**: Use the `binds` parameter to set a new name for the return value across all postconditions in the contract.
118118

119119
```rust
120120
#[contract(
121121
binds: new_value,
122122
ensures: new_value > old_value,
123123
)]
124-
fn increment(old_value: i32) -> i32 { old_value + 1 }
124+
fn increment(old_value: i32) -> i32 { /* ... */ }
125125
```
126126

127-
**2. Closure Argument Name**: Write the postcondition as a closure. This has the highest precedence and affects only that single condition.
127+
**2. Closure Binding**: Write the postcondition as a closure. This has the highest precedence and affects only that single condition.
128128

129129
```rust
130130
#[contract(
131-
// This postcondition uses the default name `output`.
131+
// This postcondition uses the default binding `output`.
132132
ensures: output.is_valid(),
133-
// This postcondition uses `val` as the name for the return value.
133+
// This postcondition binds the return value as `val`.
134134
ensures: |val| val.id() != 0,
135135
)]
136136
fn create_data() -> Data { /* ... */ }
137137
```
138138

139-
**3. Combined Name Settings**: When both are used, the name from the closure argument always takes precedence for its specific condition, while other postconditions fall back to the contract-wide name.
139+
**3. Binding Precedence**: The closure's binding takes precedence; same as in Rust. Plain postconditions still use the contract-wide binding.
140140

141141
```rust
142142
// A function where 'output' is an argument name, requiring a different name.
@@ -151,7 +151,7 @@ fn create_data() -> Data { /* ... */ }
151151
fn calculate_even_result(output: i32) -> i32 { /* ... */ }
152152
```
153153

154-
***4. Beyond Names: Destructuring Return Values***
154+
**4. Beyond Names: Destructuring Return Values**
155155

156156
The `binds` parameter also lets you destructure return values, making complex postconditions easier to read and write. You can use any valid Rust pattern, including tuple patterns, struct patterns, or even more complex nested patterns.
157157

@@ -163,7 +163,7 @@ use anodized::contract;
163163
binds: (a, b),
164164
// Postconditions can now use the bound variables `a` and `b`.
165165
ensures: a <= b,
166-
// Can also reference the original arguments.
166+
// They can also reference the arguments.
167167
ensures: (a, b) == pair || (b, a) == pair,
168168
)]
169169
fn sort_pair(pair: (i32, i32)) -> (i32, i32) { /* ... */ }

0 commit comments

Comments
 (0)