Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- macro_rules! cfg_prefix {
- (
- #[cfg($($cond:tt)*)]($($pos:tt)*)
- #[cfg(else)]($($neg:tt)*)
- $($rest:tt)*
- ) => {
- #[cfg($($cond)*)]
- $($pos)* $($rest)*
- #[cfg(not($($cond)*))]
- $($neg)* $($rest)*
- }
- }
- pub struct MyStruct<T, #[cfg(test)] U>(Option<T>, #[cfg(test)] Option<U>);
- cfg_prefix! {
- #[cfg(test)](impl<T, U> MyStruct<T, U>)
- #[cfg(else)](impl<T> MyStruct<T>)
- {
- pub fn new() -> Self {
- #[cfg(test)]
- return MyStruct(None, None);
- #[cfg(not(test))]
- return MyStruct(None);
- }
- }
- }
- #[test]
- fn test() {
- <MyStruct<i32, i32>>::new();
- panic!("In a test");
- }
- #[cfg(not(test))]
- pub fn main() {
- <MyStruct<i32>>::new();
- panic!("Not in a test");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement