bodoni / svg

Composer and parser for SVG
Other
302 stars 44 forks source link

Add Data::add method #51

Closed Palladinium closed 3 years ago

Palladinium commented 3 years ago

Data is essentially a thin wrapper around a Vec<Command> with nice syntactic sugar, but there doesn't seem to be a way to pass Commands directly into the buffer, and sometimes the syntactic sugar isn't the easiest way to go about things. This PR adds just that.

IvanUkhov commented 3 years ago

Thank you! Can you please give an example where this method would be preferred?

Palladinium commented 3 years ago

In my use case, I'm procedurally generating SVG paths, and I have a bunch of structs that construct path segments through Into<Command>.

Without this PR, my options are:

With this PR, I can write code like:

Data::default()
  .move_to((10.0, 0.0))
  .add(Thing.into())
  .move_to((30.0, 0.0))
  .add(Thing.into())
  .close()

Which matches the way Document::add() looks.

IvanUkhov commented 3 years ago

Good points! Thank you.