assert-impl-0.1.3/.gitignore010064400007650000024000000000361333314400100141510ustar0000000000000000/target **/*.rs.bk Cargo.lock assert-impl-0.1.3/.travis.yml010064400007650000024000000001631333315047400143060ustar0000000000000000language: rust rust: - stable - beta - nightly matrix: allow_failures: - rust: nightly cache: cargo assert-impl-0.1.3/Cargo.toml.orig010064400007650000024000000005771333326662200151000ustar0000000000000000[package] name = "assert-impl" version = "0.1.3" authors = ["Xidorn Quan "] description = "Macro for static assert types implement a trait or not" repository = "https://github.com/upsuper/assert-impl" license = "MIT" keywords = ["macro", "assert", "static", "impl"] readme = "README.md" [badges] travis-ci = { repository = "upsuper/assert-impl", branch = "master" } assert-impl-0.1.3/Cargo.toml0000644000000016030000000000000113320ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "assert-impl" version = "0.1.3" authors = ["Xidorn Quan "] description = "Macro for static assert types implement a trait or not" readme = "README.md" keywords = ["macro", "assert", "static", "impl"] license = "MIT" repository = "https://github.com/upsuper/assert-impl" [badges.travis-ci] branch = "master" repository = "upsuper/assert-impl" assert-impl-0.1.3/LICENSE010064400007650000024000000020371333315011500131740ustar0000000000000000Copyright (c) 2018 Xidorn Quan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. assert-impl-0.1.3/README.md010064400007650000024000000013351333326661300134610ustar0000000000000000Macro 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); ``` assert-impl-0.1.3/src/lib.rs010064400007650000024000000046501333326640400141060ustar0000000000000000//! 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: //! ``` //! # #[macro_use] extern crate assert_impl; //! # struct C; //! # struct Java; //! # struct JavaScript; //! # struct Python; //! # struct Rust; //! # trait StaticTyping {} //! # impl StaticTyping for C {} //! # impl StaticTyping for Java {} //! # impl StaticTyping for Rust {} //! 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: //! ```compile_fail //! # #[macro_use] extern crate assert_impl; //! # struct C; //! # struct Java; //! # struct JavaScript; //! # struct Python; //! # struct Rust; //! # trait StaticTyping {} //! # impl StaticTyping for C {} //! # impl StaticTyping for Java {} //! # impl StaticTyping for Rust {} //! assert_impl!(StaticTyping: JavaScript); //! ``` //! //! ```compile_fail //! # #[macro_use] extern crate assert_impl; //! # struct C; //! # struct Java; //! # struct JavaScript; //! # struct Python; //! # struct Rust; //! # trait StaticTyping {} //! # impl StaticTyping for C {} //! # impl StaticTyping for Java {} //! # impl StaticTyping for Rust {} //! assert_impl!(!StaticTyping: Rust); //! ``` #[macro_export] macro_rules! assert_impl { ($trait:path: $($ty:ty),+) => {{ struct Helper(T); trait AssertImpl { fn assert() {} } impl AssertImpl for Helper {} $( Helper::<$ty>::assert(); )+ }}; (!$trait:path: $($ty:ty),+) => {{ struct Helper(T); trait AssertImpl { fn assert() {} } impl AssertImpl for Helper {} trait AssertNotImpl { fn assert() {} } $( impl AssertNotImpl for Helper<$ty> {} Helper::<$ty>::assert(); )+ }}; ($trait:path: $($ty:ty,)+) => (assert_impl!($trait: $($ty),+)); (!$trait:path: $($ty:ty,)+) => (assert_impl!(!$trait: $($ty),+)); }