I found this intro extremely helpfull, especially the part around 6:35. However I have one question: Wouldn't it make more sense to put the trait bounds of the Logger Service implementation directly on the Logger struct (or at least the Logger impl block)? After all, an e.g. Logger implementation doesn't really make sense, does it? Or is that just not possible with (current) rust?
Yes and no. A Logger won't make sense, that's true, but by moving the trait bounds to the trait impl block you can implement multiple logger implementations for different inner services. The one around 6:35 is for services that deal with hyper Requests, but what if you don't have HTTP and still want to log something, e.g with gRPC or on Lambda? That's a new impl for different trait bounds. That's how you can keep one service but adapt. The best thing: You can be as generic or as specific as you want to be. Defining a trait bound in the struct will limit you in that regard.
Thanks for sharing this presentation!
I found this intro extremely helpfull, especially the part around 6:35. However I have one question: Wouldn't it make more sense to put the trait bounds of the Logger Service implementation directly on the Logger struct (or at least the Logger impl block)? After all, an e.g. Logger implementation doesn't really make sense, does it? Or is that just not possible with (current) rust?
Yes and no. A Logger won't make sense, that's true, but by moving the trait bounds to the trait impl block you can implement multiple logger implementations for different inner services. The one around 6:35 is for services that deal with hyper Requests, but what if you don't have HTTP and still want to log something, e.g with gRPC or on Lambda? That's a new impl for different trait bounds. That's how you can keep one service but adapt. The best thing: You can be as generic or as specific as you want to be. Defining a trait bound in the struct will limit you in that regard.
@sbaumg but if you have a generic trait impl you can't have any others, right?
Very interesting!
Thank you, I think I got it down.