April 2026
Intermediate
631 pages
16h 20m
English
In this section, we’ll provide some practice questions to help reinforce your learning. The exercise questions cover almost all the concepts introduced in the chapter. Solutions to each exercise will follow in Section 15.5.
Expanding a macro for generating multiple functions with return expressionsConsider the following code. Show the expansion part of this code, especially for the invocation to macro.
macro_rules! make_functions { ($($func_name:ident: $return_type:ty => $return_expr:expr),+) => { $( fn $func_name() -> $return_type { $return_expr } )+ };}make_functions!(foo: i32 => 42, bar: String => "hello world".to_owned());fn main() { let result1 = foo(); let result2 = bar(); println!("foo result: {}", result1); ...
Read now
Unlock full access