My question is about function takes_a_writer(). To make this function take a Writer as an argument, I have to specify the actual inner type of that Writer (Vec<u8>), even though it would make no difference. (Or would it?)
In this example it's easy to just add a type parameter to takes_a_writer(), but if Writer contains many such inner types, that means every function that takes such a struct has to have all those type parameters as well. Is there a better way?
The compiler needs to know what memory layout the argument will have in order to complie. If you want to define a set of functions that each takes a different kind of Writer, that’s what generics are for:
Oh, in the case where Writer has just this one inner, this actually makes it nicer. But when there are more type parameters, I think keeping track of their order quickly gets confusing.
I mean... how many parameters are we talking about here? Three? Five? Ten?
If takes_a_writer should, in fact, accept any Writer<W>, then the sensible thing to do is add W as a type parameter. Using impl Write can make that slightly cleaner. But if you're reluctant to add another type parameter because Writer already has 10, well... a struct with that many inner types that are all generic is probably already trying to pull together too many unrelated things, and should be split up or something.