| Crates.io | double-derive |
| lib.rs | double-derive |
| version | 0.2.8 |
| created_at | 2025-06-02 09:45:13.076484+00 |
| updated_at | 2025-10-23 11:49:50.983549+00 |
| description | Implementations of macros for crate double-trait |
| homepage | |
| repository | https://github.com/pacman82/double-trait |
| max_upload_size | |
| id | 1697813 |
| size | 37,738 |
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));
}
}