lipanski / mockito

HTTP mocking for Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow naming the type returned by Server::new() (don't use impl Trait)

mstange opened this issue · comments

Server::new() currently returns impl DerefMut<Target = Server>. Could it return a nameable type instead? This would make it easier to store it in a struct, like I'm doing here: https://github.com/mstange/symsrv/blob/a602ebca095f1ea4817839aa83abe4d359fd121c/tests/integration_tests/main.rs#L54

Also see this proposal for an API guideline which would discourage the use of impl Trait for return types in library APIs.

@mstange I had to do that in order to avoid exposing the deadpool type, since that's an implementation detail that might change in the future (the returned server is part of a server pool maintained with deadpool). not sure what other options we have. doesn't the Box approach work for you?

maybe I could implement my own struct to hide the deadpool type and then implement Deref on it.

Yes, wrapping an internal type into a newtype would be a fine solution.

The Box approach works but doesn't look very clean.

@mstange I've addressed this in 0.32.3 - the crate now exposes the ServerGuard struct. Check the release notes or the docs for more details.

Thanks!