double-derive

Crates.iodouble-derive
lib.rsdouble-derive
version0.2.8
created_at2025-06-02 09:45:13.076484+00
updated_at2025-10-23 11:49:50.983549+00
descriptionImplementations of macros for crate double-trait
homepage
repositoryhttps://github.com/pacman82/double-trait
max_upload_size
id1697813
size37,738
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