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

Example - an HTTP tester

Let's see how the macro expansion functions by working through a custom macro with overlapping patterns. This macro implements a small language, designed for describing simple HTTP GET/POST tests using the hyper library. Here's a sample of what the language looks like without the enclosing macro calls:

http://google.com GET => 302http://google.com POST => 411

The first line makes a GET request to Google, and expects a return code, 302 (Moved). The second one makes a POST request to the same place, and expects a return code 411 (Length Required). This is very simplistic but quite sufficient for our purposes.

Hyper is Rust's de facto standard HTTP library, which supports both server and client operations. We're interested ...

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