Rust provides a list of designators, which help us create units, such as functions, and execute expressions in macros.
We will require the Rust compiler and any text editor to develop the Rust code snippet.
Follow the mentioned steps to implement this recipe:
- Create a file named
sample_designator.rs
, and open it in your text editor. - Write the code header with the relevant information:
//-- ######################### //-- Task: Implementing designator //-- Author: Vigneshwer.D //-- Version: 1.0.0 //-- Date: 26 March 17 //-- #########################
- Create a macro named
create_function
, which accepts a designator as an argument:
macro_rules! create_function { ($func_name:ident) => ( fn $func_name() { // The `stringify!` macro converts an `ident` into a string. println!("You called {:?}()", stringify!($func_name...