asomers / mockall

A powerful mock object library for Rust
Apache License 2.0
1.5k stars 62 forks source link

Is there any mechanism to take ownership of arguments in withf? #488

Closed stan-irl closed 1 year ago

stan-irl commented 1 year ago

Im trying to mock out a grpc service interface at the moment but its not currently possible to access tonic request fields without calling req.into_inner() which consumes the request: https://docs.rs/tonic/latest/tonic/struct.Request.html#method.into_inner. Its also not possible to clone the request. This means its not possible to match with withf.

This pattern seems to be pretty consistent across the board. Its the same in hyper: https://github.com/hyperium/hyper/issues/1300.

I think matching against requests is a pretty common use case for this library. Is there any other way to achieve this? or would it be possible to support it?

asomers commented 1 year ago

Nope. withf can't possibly pass arguments by ownership, because then the arguments wouldn't be available for a subsequent returner, like .returning(). I suggest you:

stan-irl commented 1 year ago

ok no worries. this is great info - I will just panic in the returner. for now thats good enough. thanks for the quick response!