patterns icon indicating copy to clipboard operation
patterns copied to clipboard

Add init-struct pattern

Open virtualritz opened this issue 1 year ago • 3 comments
trafficstars

See here for a more exhaustive description.

virtualritz avatar Jan 29 '24 13:01 virtualritz

In general, I'm not sure, that this values an own article.

I also see it more as an idiom, than a pattern.

Can you look into https://github.com/rust-unofficial/patterns/blob/main/src/idioms/ctor.md and see what you would want to add there?

Also, there is something written down about that topic here already:

  • https://doc.rust-lang.org/book/ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
  • https://doc.rust-lang.org/book/appendix-03-derivable-traits.html#default-for-default-values

P.S.: Before writing an article and making a PR it's always better to open an issue/discussion before as stated in our Contribution guidelines, so there is no energy being wasted on either side.

simonsan avatar Jan 29 '24 14:01 simonsan

In general, I'm not sure, that this values an own article.

I also see it more as an idiom, than a pattern.

I find that many Rustaceans, even people using the language for a while are oblibious of this pattern/idiom. Especially people coming from other languages. So I though rather than adding it as a "footnote" somehere on an existing page, I make a dedicated one.

Today I ran into this again here. I would say overall I ran into people with considerable Rust experience being unaware of this maybe half a dozen times last year.

That's why I decided to write this. But it only took me 20mins. So if the PR is rejected, it's not a biggie. :grin:

virtualritz avatar Jan 29 '24 15:01 virtualritz

So I though rather than adding it as a "footnote" somehere on an existing page, I make a dedicated one.

It doesn't need to be only a footnote in said existing article. You can write a few lines about it as well and then link the both links I posted for example, to make people aware, that this topic is explained in the book.

simonsan avatar Jan 30 '24 10:01 simonsan