Skip to content

Add new pattern: use custom traits to avoid complex type bounds#437

Merged
simonsan merged 4 commits into
rust-unofficial:mainfrom
neithernut:trait-for-bounds
Dec 10, 2025
Merged

Add new pattern: use custom traits to avoid complex type bounds#437
simonsan merged 4 commits into
rust-unofficial:mainfrom
neithernut:trait-for-bounds

Conversation

@neithernut

Copy link
Copy Markdown
Contributor

Introducing traits as an abstraction should be obvious enough in many Rust projects. However, I often found myself introduce "random" type bounds involving Fn that would grow unwieldy first until I finally introduced a new trait. So maybe this is advise some people, especially new Rust users, will find useful.

I did not include a Motivation section because I felt it was redundant. I also did not (yet) write a Discussion section. There are probably some similar uses of type classes in functional programming languages that we could refer to.

Introducing traits as an abstraction should be obvious enough in many
Rust projects. However, I often found myself introduce "random" type
bounds involving `Fn` that would grow unwieldy first until I finally
introduced a new trait. So maybe this is advise some people, especially
new Rust users, will find useful.
@neithernut

Copy link
Copy Markdown
Contributor Author

The style check currently fails, but I feel it's suggestions are wrong: they would result in a line longer than 80 characters, and they clearly don't handle footnotes correctly. Any suggestions for resolving this?

@simonsan

simonsan commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Sorry for the longer wait, I'll look into reviewing this in the upcoming week! ✊🏽

Actually, it's so well written, that I'll merge it right away. Thanks a lot! 🚀

simonsan
simonsan previously approved these changes Dec 10, 2025
Comment thread src/SUMMARY.md Outdated
@simonsan simonsan marked this pull request as ready for review December 10, 2025 10:46
@simonsan simonsan merged commit b43f019 into rust-unofficial:main Dec 10, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants