A question about syntax

When i using actix-web to build my application, i found a special syntax that is "Response<B=Body>” at definition structure. I can’t understand this syntax, and i try to find the description about this but I failed. So could you tell me some knowledge about this syntax or tell me how to find an explanation for it ? Thanks very much.

This is a default generic parameter. The idea is that you can declare a generic type or trait and have some of the type parameters assume fixed values when they're not specified explicitly:

struct Foo<T = String>(T);

// equivalent to `let x: Foo<String> = ...`
let x: Foo = Foo(String::from("thunk"));
// type parameter specified explicitly
let y: Foo<i32> = Foo(17);

You can also use the explainers tool for finding out what a particular piece of syntax means.

I see.Thanks a lot!

1 Like

Oh, I forgot that there's one other, unrelated place where this syntax comes up, in constraints involving associated types:

// constrain `I` to any type that implements `Iterator` with the
// associated type `Item = i32`
fn second<I: Iterator<Item = i32>>(it: &mut I) -> Option<i32> {
    it.nth(1)   
}

Thanks for sharing a link to explainers! I've never seen this before and imagine it'll be quite handy.
It doesn't currently seem to have a hint for this case, so I've filed a ticket.

1 Like