#static-assert #static #assert #macro #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

#2105 in Rust patterns

Download history 2414/week @ 2024-11-16 1466/week @ 2024-11-23 1947/week @ 2024-11-30 2047/week @ 2024-12-07 2125/week @ 2024-12-14 714/week @ 2024-12-21 1142/week @ 2024-12-28 1236/week @ 2025-01-04 2421/week @ 2025-01-11 1554/week @ 2025-01-18 1351/week @ 2025-01-25 3437/week @ 2025-02-01 1757/week @ 2025-02-08 1251/week @ 2025-02-15 1936/week @ 2025-02-22 1711/week @ 2025-03-01

6,874 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 this should fail to build:

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

lib.rs:

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);

No runtime deps