double-trait

Crates.iodouble-trait
lib.rsdouble-trait
version0.2.8
created_at2025-06-04 18:12:02.402607+00
updated_at2025-10-23 11:49:59.386623+00
descriptionA procedural macro to derive a mirror of a trait designed to make it easier to implement test doubles.
homepage
repositoryhttps://github.com/pacman82/double-trait
max_upload_size
id1700722
size11,892
Markus Klein (pacman82)

documentation

README

Double Trait

A procedural macro to derive a mirror of a trait designed to make it easier to implement test doubles.

Usage

// 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));
    }
}
Commit count: 77

cargo fmt