How to define a pass macro (identifier or NOP)?

When porting code from another language, I would like to save some expressions, such as macros likely/ unlikelyas a dummy macro.

Usage example:

if expr_nop!(expression) { 
    code;
}

... which should be exactly the same as the entry:

if (expression) { 
    code;
}

What is a good fail-safe macro in rust that can be used as a no-op?

I currently have:

macro_rules! expr_nop { ($body:expr) => { $body } }

Is this correct or should it be written differently?

+4
source share
1 answer

I would say that your macro ...

macro_rules! expr_nop { ($body:expr) => { $body } }

... correctly.

: , . , , expr_nop(i32) , i32 , ( , if expr_nop!(i32) {...} , ).

, ( ) , , , .

+2

Source: https://habr.com/ru/post/1651004/


All Articles