O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercises

  1. Write a macro that takes an arbitrary number of elements and outputs an unordered HTML list in a literal string. For instance, html_list!([1, 2]) => <ul><li>1/<li><li>2</li></ul>.
  2. Write a macro that accepts the following language:
        language = HELLO recipient;        recipient = <String>;

For instance, the following strings would be acceptable in this language:

        HELLO world!        HELLO Rustaceans!

Make the macro generate code that outputs a greeting directed to the recipient.

  1. Write a macro that takes either of these two arbitrary sequences:
        1, 2, 3        1 => 2; 2 => 3

For the first pattern, it should generate a vector with all the values. For the second pattern, it should generate a HashMap with key-value pairs.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required