Replies: 1 comment 1 reply
-
Hi, any update on this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Mockall is a great crate that's used by lots of projects, but its syntax isn't perfect. It reflects language limitations, historical implementation details, and the legacies of its predecessors. In particular, it has a few oft-noted problems:
#[automock]
doesn't work on structs with more than one trait impl, or structs with both a trait impl and inherent methods.#[automock(type Key=u16; type Value=i32;)]
, but this would get cumbersome if Mockall ever supports more types of metaitems.#[concretize]
attribute, but its implementation is hacky.Instead, I propose replacing all of Mockall's syntax with a new Derive macro, which would solve both of these problems. The first, it would solve by generating the code in pieces. The second, it would solve by standard helper attributes. Its syntax would look like this:
With this syntax,
mock!
would only be necesary when mocking structs or traits from external traits. Also, it would be easy to add more helper attributes. For example:#[concretize]
, which already exists#[as]
, for mocking traits with associated constants#[skip]
, as discussed in Support returning of generic parameter usingmock!
macro #536, Skip Generating mock methods #471, and Warning: mocked function never used #410#[default]
to make a method return a default value, so you won't have to dosomething like
.return_const(())
everywhere.#[expect_name(something)]
, which would allow implementing multiple traitswhose methods have the same names, as discussed in How to mock multiple impls of generic struct instances? #271.
I doubt I'll hear any objections to these new features, so what remains is mainly a question of deciding how to name things. That and, of course, finding the time to implement it all ;)
Beta Was this translation helpful? Give feedback.
All reactions