Skip to content

Conversation

@fredszaq
Copy link

@fredszaq fredszaq commented Jan 9, 2026

Resolves #316

This PR depends on #533 (I will mark this PR as non-draft once #533 is merged; for now, you will see changes from both PRs in the diff).

Synopsis

This adds an implementation of a Default derive, with a few improvements over the one bundled with Rust:

  • no constraints on generic types by default (useful, for example, if your types only contain Option<T>)
  • the ability to set a custom bound on structs/enums via #[default(bound(...))]
  • the ability to set default values on fields via #[default(expr(...))]
  • the ability to set a non-unit default variant for enums (this needs to be annotated with #[default], as with the standard derive)

Solution

This uses the moved Bounds attribute from #533; otherwise, the implementation is quite straightforward.

Checklist

  • Documentation is updated (if required)
  • Tests are added/updated (if required)
  • CHANGELOG entry is added (if required)

@fredszaq fredszaq changed the title Default derive Add Default derive Jan 9, 2026
@tyranron tyranron added feature New derive or feature k::api Related to API (application interface) labels Jan 9, 2026
@tyranron tyranron added this to the next milestone Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New derive or feature k::api Related to API (application interface)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for deriving Default

2 participants