New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for trait's associated const #97
Comments
|
Hi @asomers, Thank you for this very useful library. I have had the above issue that seems to be caused by the lack of support for trait consts. However, in the case you know a workaround already, I will appreciate it if you can let us know. Best regards, |
|
I don't think this is something I've tried yet, so it doesn't surprise me that it doesn't work. But I doubt it's difficult to add. What happens if you do this: mock! {
S {
const C: &'static str = "foo";
}
trait A {
type T = isize;
const C: &'static str = "Mock";
fn foo(t: isize) -> bool;
}
} |
|
I get a different vague build error:
|
|
Yep, that means I have some work to do. Unfortunately, I can't suggest any workaround. However, you'll get a better error message if you build Mockall with the "nightly" feature. |
automock can now mock a trait impl with an associated const. It can't mock the trait declaration, because in that case there's no way to set the value of the associated const on the mock struct. Of course, if the trait itself has a default value for the const, then automock will work. automock can now mock a struct impl with an associated const. mock! can now mock structs with both inherent associated consts, and associated consts on their trait impls. Fixes #97
The following code, when compiled, throws the "missing C in an implementation" error:
The text was updated successfully, but these errors were encountered: