Hi,
So I'm still trying to find my way around Rust's design, and I already like it a lot - thanks everyone for your work, both on the compiler, the library, the crates, and the community!
Right, now for the question. So a trait, let's call it Output, has a <W: Write> parameter. A struct wants to hold an object that implements the Output trait, but the struct itself does not really care at all about the writer itself - it is more or less an internal implementation detail of the Output structure, although, of course, I know it matters to the compiler But I could not figure out how to put W in the definition of the struct that wants to have <O: Output> as a parameter - the compiler kept saying W was unused, so in the end I had to resort to what feels like a hack with PhantomData.
Here's the code in question:
- the Output trait: src/output.rs · e2d2e1abad74b0a35141a16125e70826fef047b0 · Peter Pentchev / hd-realtime · GitLab
- the struct that wants to hold an Output-like object: src/format.rs · e2d2e1abad74b0a35141a16125e70826fef047b0 · Peter Pentchev / hd-realtime · GitLab
And sure, I could box the object, but that felt like an even weirder hack - I can't help but feel that there ought to be a way to express this using parameters, but I cannot figure out how.
Thanks in advance for the inevitable insight-inducing cluebat And keep up the great work!
G'luck,
Peter