You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -196,6 +196,38 @@ fn foo() {}
196
196
modfoo_fuzz {}
197
197
```
198
198
199
+
#### Serde field attributes on function arguments
200
+
201
+
The `test_fuzz` macro allows [Serde field attributes] to be applied to function arguments. This provides another tool for dealing with difficult types.
202
+
203
+
The following is an example. Traits `serde::Serialize` and `serde::Deserialize` cannot be derived for `Context` because it contains a `Mutex`. However, `Context` implements `Default`. So applying `#[serde(skip)]` to the `Context` argument causes it to be skipped when serializing, and to take its default value when deserializing.
204
+
205
+
```rust
206
+
usestd::sync::Mutex;
207
+
208
+
// Traits `serde::Serialize` and `serde::Deserialize` cannot be derived for `Context` because it
209
+
// contains a `Mutex`.
210
+
#[derive(Default)]
211
+
structContext {
212
+
lock:Mutex<()>,
213
+
}
214
+
215
+
implCloneforContext {
216
+
fnclone(&self) ->Self {
217
+
Self {
218
+
lock:Mutex::new(()),
219
+
}
220
+
}
221
+
}
222
+
223
+
#[test_fuzz::test_fuzz]
224
+
fntarget(#[serde(skip)] context:Context, x:i32) {
225
+
assert!(x>=0);
226
+
}
227
+
```
228
+
229
+
Note that when Serde field attributes are applied to an argument, the `test_fuzz` macro performs no other [conversions] on the argument.
230
+
199
231
### `test_fuzz_impl` macro
200
232
201
233
Whenever the [`test_fuzz`] macro is used in an `impl` block,
@@ -516,6 +548,7 @@ We reserve the right to change the format of corpora, crashes, hangs, and work q
0 commit comments