https://github.com/upsuper/assert-impl
Macro for static assert that types implement a trait or not.
https://github.com/upsuper/assert-impl
rust rust-macro
Last synced: 3 months ago
JSON representation
Macro for static assert that types implement a trait or not.
- Host: GitHub
- URL: https://github.com/upsuper/assert-impl
- Owner: upsuper
- License: mit
- Created: 2018-08-09T23:43:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-28T21:39:10.000Z (over 6 years ago)
- Last Synced: 2024-05-01T23:06:48.373Z (about 1 year ago)
- Topics: rust, rust-macro
- Language: Rust
- Size: 4.88 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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:
```rust
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:
```rust
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:
```rust
assert_impl!(StaticTyping: JavaScript);
assert_impl!(!StaticTyping: Rust);
```