I'm writing some code that deals with file formats that are basically nested. I'd like this to work with a Reader
so that is generic where the input comes from.
So far, my outermost wrapper is defined like:
struct Outer<'a> { reader: &'a mut (io::Reader+'a), ... }
with a constructor signature like:
impl<'a> Outer<'a> { put fn new<'b>(mut rd: &'b mut (io::Reader+'b)) -> MyResult> { ... } }
this does seem to largely work, but the signatures get a little awkward. My Outer
struct would then implement some other trait which would be embedded in a similar manner in some other struct that implements the next layer inside the file format onion.
My question: is this the best way to do this. It does allow the user some flexible in how everything is allocated, even though the thing that is the Reader
can't really be used any more.
Would I be better off embedding the trait item, and making it a parameter of the Outer
class. Something like:
struct Outer<'a, T> where T: io::Reader+'a+Sized { reader: T, ... }