#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

#2302 in Rust patterns

Download history 2757/week @ 2024-07-19 1681/week @ 2024-07-26 1015/week @ 2024-08-02 1337/week @ 2024-08-09 1428/week @ 2024-08-16 1483/week @ 2024-08-23 2505/week @ 2024-08-30 3220/week @ 2024-09-06 2867/week @ 2024-09-13 2849/week @ 2024-09-20 2028/week @ 2024-09-27 1193/week @ 2024-10-04 1515/week @ 2024-10-11 2128/week @ 2024-10-18 1554/week @ 2024-10-25 1379/week @ 2024-11-01

6,775 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