#different #version #compile-time #assert #type #compatible #assertions

assert-type-eq

Macro to assert types across potentially different crate versions are compatible

1 unstable release

Uses old Rust 2015

0.1.0 Aug 31, 2017

#2939 in Rust patterns

Download history 1999/week @ 2024-03-13 855/week @ 2024-03-20 1429/week @ 2024-03-27 998/week @ 2024-04-03 1576/week @ 2024-04-10 862/week @ 2024-04-17 1488/week @ 2024-04-24 1649/week @ 2024-05-01 2215/week @ 2024-05-08 2881/week @ 2024-05-15 4449/week @ 2024-05-22 3976/week @ 2024-05-29 1492/week @ 2024-06-05 1972/week @ 2024-06-12 1976/week @ 2024-06-19 1986/week @ 2024-06-26

7,735 downloads per month
Used in 3 crates

Apache-2.0

6KB

assert-type-eq

Build Status crates.io

This Rust crate adds a macro to assert at compile time that certain types are the same. This is useful when using the same crate via different dependencies, which may bring in different versions of the same crate, which Rust considers to have incompatible types. In most circumstances this will by itself lead to a compile-time error, however when using runtime structures such as Any or TypeMap, this will not cause compile-time issues, but rather runtime problems with missing or unexpected data. By using this crate, the different versions of the same crate can be asserted to be compatible, turning a runtime error into a compile-time error.


lib.rs:

Statically assert that types from potentially different crate versions via different dependencies are identical.

Until RFC 1977 (public dependencies) is accepted, the situation where multiple different versions of the same crate are present is possible. In most situations this will simply cause code to not compile, as types mismatch, however with runtime structures like TypeMap this leads to runtime errors (often silent!) instead. This macro allows compile-time assertion that types via different dependencies are identical, and will interoperate, which is easier to debug than runtime errors.

Usage:

#[macro_use]
extern crate assert_type_eq;

pub mod my_crate {
    pub struct MyStruct;
}

mod a {
    pub use super::my_crate;
}

mod b {
    pub use super::my_crate;
}

assert_type_eq!(
    my_crate::MyStruct,
    a::my_crate::MyStruct,
    b::my_crate::MyStruct,
);

fn main() {
    // ...
}

Specify all versions of the same type via different dependencies. Any types that do not match the first type in the macro will cause a compile-time error.

No runtime deps