Hey!
I'm trying to use double crate to mock traits. So far so good, except when the trait in question has not clonable arguments or return types, like Read
.
The read
method asks for a &mut [u8]
as argument and a io::Result<usize>
(equivalent to Result<usize, io::Error>
) as return. Both &mut [u8]
and io::Error
don't implement Clone
.
So, the double's Mock is defined as:
pub struct Mock<C, R> where
C: Clone + Eq + Hash,
R: Clone, { /* fields omitted */ }
And the documentation states:
Used for tracking function call arguments and specifying a predetermined return value or mock function.
See the crate documentation for more substantial examples, including some that demonstrate how to use Mock for methods that have multiple arguments as well as methods with argument or return types that do not implement Clone.
But I was unable to find anything mentioning how to mock not clonable things in the documentation.
How can I mock trait like Read
with double
? There is a way to encapsulate not clonable types in a clonable container?