test_fuzz/convert.rs
1pub trait FromRef<T> {
2 fn from_ref(_: &T) -> Self;
3}
4
5impl<T, U> FromRef<T> for U
6where
7 T: Clone,
8 U: From<T>,
9{
10 fn from_ref(value: &T) -> Self {
11 Self::from(value.clone())
12 }
13}
14
15/// Trait whose implementation is required by the [`test_fuzz` macro]'s [`convert`] option.
16///
17/// The reason for using a non-standard trait is to avoid conflicts that could arise from blanket
18/// implementations of standard traits. For example, trying to use `From` instead of
19/// `test_fuzz::Into` can lead to errors like the following:
20///
21/// ```text
22/// conflicting implementation in crate `core`:
23/// - impl<T> From<T> for T;
24/// ```
25///
26/// Such errors were observed in the [Substrate Node Template] [third-party test].
27///
28/// [`convert`]: https://github.com/trailofbits/test-fuzz/blob/master/README.md#convert--x-y
29/// [`test_fuzz` macro]: https://github.com/trailofbits/test-fuzz/blob/master/README.md#test_fuzz-macro
30/// [Substrate Node Template]: https://github.com/trailofbits/test-fuzz/blob/master/third-party/patches/substrate_node_template.patch
31/// [third-party test]: https://github.com/trailofbits/test-fuzz/blob/master/third-party/tests/third_party.rs
32pub trait Into<T> {
33 fn into(self) -> T;
34}