Greetings everyone, my first post on the forum (was reluctant to posting this on SO). I have very recently started working with Rust and have never delved into this programming paradigm before (which is honestly fascinating). The drawback I'm experiencing right now is having to rethink everything about design and behaviour to what I'm more familiar with.
I've been wanting to port yattag over to rust as I need to generate an enormously large number of HTML files as fast as possible; however before doing that I want to properly learn the language and the paradigm itself.
For instance--I would require a Tag struct which is able to maintain a property of itself like so:
Will compile. You need to Box up the inner Tag so that Rust can figure out the size, but since that would require making a Tag to instantiate a Tag, you can use Option so that you can initialize a tag with None.
I would imagine that you'd actually want this, though:
You almost always want to start with structs that own their contents, rather than just hold references. Specifically, &Vec seems unusual. But it does depend on what you're doing.
Woops! Thanks for pointing that out. Giving it another thought, structs owning their own content does indeed make more sense. Thanks for your code suggestion
Oh wow, that's much simpler indeed. Only Init would be used by more than one struct; rest is specific to each struct so just implementing them is much better. Thanks again