How can I use fields of a mocked struct using mockall?

I'm hoping to make a stateful mock object by using mockall to mock a struct with fields I control similar to the following:

struct Counter {
    pub count: u8,
}

mock! {
    pub Counter {}
}

let test = MockCounter::new();
dbg!("Count is {:?}", test.count)

but this fails to compile, complaining that there is no field count on type MockCounter. Is there any way to access custom fields on a mock object or otherwise track custom state? Only other option that comes to mind is static variables, but I would prefer to stay in the scope of mock object definitions for cleanliness and simplicity if possible.

I'm not familiar with the crate, but it seems there's no direct support.

1 Like

Drat, that's as I feared. Ok, time to switch to fakes :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.