1 unstable release
Uses old Rust 2015
0.1.0 | Aug 31, 2017 |
---|
#2939 in Rust patterns
7,735 downloads per month
Used in 3 crates
6KB
assert-type-eq
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.