-
Hello everybody, could you give me a hint on how to deal with lifetimes within the mock! macro block? I want to do something like this: use mockall::*;
use mockall::predicate::*;
use std::fmt;
#[cfg(test)]
mod tests {
use super::*;
mock! {
MyStruct {}
impl fmt::Debug for MyStruct {
fn fmt(&self, f: &mut fmt::Formatter<'a>) -> fmt::Result {
f.write_str("MyStruct")
}
}
}
#[test]
fn test_clone() {
let mut mock1 = MockMyStruct::new();
mock1.expect_fmt()
.returning(|f| f.write_str("MyMock"));
assert_eq!("MyMock", format!("{:?}", mock1));
}
} and I get a result like:
But the suggested I'm looking forward to any hint. Thanks and take care |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
LOL, what timing! The easiest course of action for you would be to upgrade Mockall to the latest version in git. As of yesterday, it will automatically generate a
|
Beta Was this translation helpful? Give feedback.
-
(also, you get to serve as Mockall's Discussions guinea pig. Let's see if Discussions are a better way to ask for help than Issues). |
Beta Was this translation helpful? Give feedback.
LOL, what timing! The easiest course of action for you would be to upgrade Mockall to the latest version in git. As of yesterday, it will automatically generate a
Debug
impl.But if you don't want to do that, then write the function signature like this. I think all three of these forms will work:
pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
pub fn fmt<'a>(&self, f: &mut Formatter<'a>) -> Result<(), Error>;
pub fn fmt(&self, f: &mut Formatter -> Result<(), Error>;