Macro anterofit::map_builder[][src]

macro_rules! map_builder {
    (|$builder:ident| $expr:expr) => { ... };
    (move |$builder:ident| $expr:expr) => { ... };
    (|mut $builder:ident| $expr:expr) => { ... };
    (move |mut $builder:ident| $expr:expr) => { ... };
}

Use in a service method body to perform an arbitrary transformation on the builder.

use anterofit::RawBody;

service! {
    trait MyService {
        fn send_whatever(&self) {
            POST("/whatever");
            // `move` and `mut` are allowed in their expected positions as well
            map_builder!(|builder| builder.body(RawBody::text("Hello, world!")))
        }
    }
}

You can even use try!() as long as the error type is convertible to anterofit::Error:

use anterofit::RawBody;
use std::fs::File;

service! {
    trait MyService {
        fn put_log_file(&self) {
            PUT("/log");
            map_builder!(|builder| {
                let logfile = try!(File::open("/etc/log"));
                builder.body(RawBody::new(logfile, None))
            })
        }
    }
}

If you just want to return a Result<RequestBuilder>, use a bare closure in your service method body.