Default generic parameter

⚓ Rust    📅 2025-06-29    👤 surdeus    👁️ 6      

surdeus

Warning

This post was published 41 days ago. The information described in this article may have changed.

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Default generic parameter

I want to wrap values in a struct that adds some logic to it. For instance, I want to have a u64 wrapper that will only allow certain values to be set to it, and that validation is done using a trait.

There is a trait implementation that allows all values (i.e. it rejects none), and it would be neat to make that the "default".

Playground

Uncommenting line 65 makes the code no longer build. I was kind of hoping that the default parameter on line 28 would be the magic sauce to make it work.

4 posts - 4 participants

Read full topic

🏷️ rust_feed