| Crates.io | double-trait |
| lib.rs | double-trait |
| version | 0.2.8 |
| created_at | 2025-06-04 18:12:02.402607+00 |
| updated_at | 2025-10-23 11:49:59.386623+00 |
| description | A procedural macro to derive a mirror of a trait designed to make it easier to implement test doubles. |
| homepage | |
| repository | https://github.com/pacman82/double-trait |
| max_upload_size | |
| id | 1700722 |
| size | 11,892 |
A procedural macro to derive a mirror of a trait designed to make it easier to implement test doubles.
// Given a trait `MyTrait` with derived dummy implementations in tests
#[cfg_attr(test, double_trait::dummies)]
trait MyTrait {
fn answer(&self) -> i32;
fn some_other_method(&self);
}
// ...
#[cfg(test)]
mod tests {
#[test]
fn test_function_using_org_trait() {
// When implementing a Stub for `MyTrait
struct Stub;
impl MyTrait for Stub {
fn answer(&self) -> i32 {
42
}
}
// Then `Stub` also implements `MyTrait`. Despite only implementing one of the methods
// explictily.
assert_eq!(42, OrgTrait::answer(&Stub));
}
}