rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
8.02k stars 366 forks source link

Fix JSON formatter bug in Strategy pattern #340

Closed tburko closed 1 year ago

tburko commented 1 year ago

Empty data would have produced invalid output: "["

simonsan commented 1 year ago

Hmm, unsure. I wouldn't consider it a bug in this case, it's simplistic example code and therefore data to be formatted should never be empty. I see, though, that if this exact code would be used in production (which it really shouldn't) there would be problems.

@MarcoIeni Thoughts on this?

MarcoIeni commented 1 year ago

It looks good to me, apart from a small comment

MarcoIeni commented 1 year ago

I will merge this. Simonsan, feel free to raise a PR if this doesn't look good to you.