Closed wcampbell0x2a closed 4 years ago
never mind, just needed to use unsafe.
It is a bit unfortunate that unsafe is needed in this seemingly standard use case. I haven't looked at the code yet, but it would seem that some better lifetime management would resolve the issue. Thoughts?
It's both a limitation of the library and a limitation of Rust.
I think the best path for faux
to solve this is to implement a better abstraction over:
when!(foo.method).then(|_| { mocked_return_object } )
When the closure is given, faux
does not know that the parameter with a lifetime is not going to be mishandled, so it has to force the user to use unsafe
or be unsound. However, the user knows, and they can tell `faux:
// made up syntax,I need to give this actual thought
when!(foo.method).return(mocked_return_object)
At that point, faux
would know the user cannot be mishandling the references in the arguments because they have no access to them!
I have been away from faux
lately due to there being a million other things in my head, but when I am back doing faux
full force, this ergonomics issue is definitely in my top priority.
Added new methods: c609864bded8b18809cf6c76d066a1db42b636c0
then_do
and then_return
that should solve the simple cases.
I am still unsure about the names but they will do for now. They should be up on the next release of faux
, whenever that may be :grin:
v0.0.6 added then_do
and then_return
to help handle some of the simple cases.
Looking into this mocking library, still relatively new to rust. Having some issues when trying to mock some object that I have that communicates with a unix socket.
Creating a mock function and this is the following code in my test file.
this is the function that is being mocked.
this is the error when I try and compile the code.
Slightly confused about this error, because of the functions being called normally before trying out this library.
Thanks for the library, just need some explanation on how to fix this code.