I am looking into the Iron source code for Response::with()
, trying to understand how it applies a tuple as modifiers to the response.
As I understand, a modifier is simply a builder object, taking in a reference to the current context (self
) and taking the object you wish to build on as a parameter (as long as you implement the modify
function).
Assuming we have the following code:
use iron::modifiers::Header;
fn hello_world(_: &mut Request) -> IronResult<Response> {
let string = get_file_as_string("./public/index.html");
let content_type = Header(ContentType(Mime(TopLevel::Text, SubLevel::Html, vec![])));
Ok(Response::with((status::Ok, string, content_type)))
}
Digging through the docs, I can see the implementation of Response::with()
in Iron is as follows:
pub fn new() -> Response {
Response {
status: None, // Start with no response code.
body: None, // Start with no body.
headers: Headers::new(),
extensions: TypeMap::new()
}
}
/// Construct a Response with the specified modifier pre-applied.
pub fn with<M: Modifier<Response>>(m: M) -> Response {
Response::new().set(m)
}
I'm struggling to see how my tuple of objects are translated into modifiers? I'd expect to see a foreach potentially iterating over each modifier, but here I simply see a set operation.
Could somebody explain the order to execution here and uncover what is actually happening?