Skip to content

Conversation

@gbonnefille
Copy link

@gbonnefille gbonnefille commented Jan 6, 2026

Default trait is useful when creating proof-of-concept tools.

Fixes #146

@google-cla
Copy link

google-cla bot commented Jan 6, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gbonnefille
Copy link
Author

@hchataing feel free to create a feature inspired by this patch (I'm not able to accept the CLA)

@hchataing
Copy link
Collaborator

Patch rebased to #147 (that was a failed experiment to see if me uploading the patch would bypass the CLA enforcement)

@hchataing hchataing closed this Jan 12, 2026
@gbonnefille
Copy link
Author

@hchataing thinking about this feature, I realized we can certainly go one step further looking at Builder pattern.
For example, adding methods like with_XXX(YYY) and then being able to write:

let packet = MyPacket::default().with_attr1(1).with_attr3(3);

I tried to implement this, but I'm still not comfortable enough with the code.

@hchataing
Copy link
Collaborator

@hchataing thinking about this feature, I realized we can certainly go one step further looking at Builder pattern. For example, adding methods like with_XXX(YYY) and then being able to write:

let packet = MyPacket::default().with_attr1(1).with_attr3(3);

I tried to implement this, but I'm still not comfortable enough with the code.

You could use this pattern to specify a subset of fields only:

MyPacket { MyPacket::default() .., attr1: 1, attr3: 3 }

I haven't seen a lot of use cases for using the with_attr() setters, in what context do you want to have this ?

@gbonnefille
Copy link
Author

I did not know the pattern you presented. So there is no more need. Thanks.

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.

[Rust] Add Default

2 participants