#static-assert #macro #assert #static #impl

assert-impl

Macro for static assert types implement a trait or not

4 releases

Uses old Rust 2015

0.1.3 Aug 10, 2018
0.1.2 Aug 10, 2018
0.1.1 Aug 10, 2018
0.1.0 Aug 9, 2018

#2235 in Rust patterns

Download history 1371/week @ 2024-12-18 867/week @ 2024-12-25 1203/week @ 2025-01-01 2187/week @ 2025-01-08 1619/week @ 2025-01-15 1532/week @ 2025-01-22 2362/week @ 2025-01-29 2657/week @ 2025-02-05 1433/week @ 2025-02-12 1662/week @ 2025-02-19 2096/week @ 2025-02-26 1388/week @ 2025-03-05 1343/week @ 2025-03-12 2685/week @ 2025-03-19 1868/week @ 2025-03-26 1113/week @ 2025-04-02

7,257 downloads per month
Used in 23 crates (15 directly)

MIT license

5KB

Macro for static assert that types implement a trait or not.

Note: this macro can only be used inside function body due to restriction of Rust.

Example

Assuming you have the following definitions:

struct C;
struct Java;
struct JavaScript;
struct Python;
struct Rust;

trait StaticTyping {}
impl StaticTyping for C {}
impl StaticTyping for Java {}
impl StaticTyping for Rust {}

This should build:

assert_impl!(StaticTyping: C, Java, Rust);
assert_impl!(StaticTyping: C, Java, Rust, );
assert_impl!(!StaticTyping: JavaScript, Python);
assert_impl!(!StaticTyping: JavaScript, Python, );

But these should fail to build:

assert_impl!(StaticTyping: JavaScript);
assert_impl!(!StaticTyping: Rust);

Macro for static assert that types implement a trait or not.

Note: this macro can only be used inside function body due to restriction of Rust.

Example

Assuming you have the following definitions:

struct C;
struct Java;
struct JavaScript;
struct Python;
struct Rust;

trait StaticTyping {}
impl StaticTyping for C {}
impl StaticTyping for Java {}
impl StaticTyping for Rust {}

This should build:

assert_impl!(StaticTyping: C, Java, Rust);
assert_impl!(StaticTyping: C, Java, Rust, );
assert_impl!(!StaticTyping: JavaScript, Python);
assert_impl!(!StaticTyping: JavaScript, Python, );

But this should fail to build:

assert_impl!(StaticTyping: JavaScript);
assert_impl!(!StaticTyping: Rust);

No runtime deps