It is not in the manual, yet it seems to be ubiquitous in packages. What’s up with that?
Edit: online search finally yielded something useful: What does @kwdef do? - #4 by j-fu
I couldn’t find it before in this forum, because I was looking for @kwdef. No: the search fails with that. What it needs is kwdef. Go figure…
It does have the virtue of having actual source code documentation, which I used last time I forgot how to use it:
This is a helper macro that automatically defines a keyword-based
constructor for the type declared in the expression typedef, which must be a
struct or mutable struct expression. The default argument is supplied by
declaring fields of the form field::T = default or field = default. If no
default is provided then the keyword argument becomes a required keyword
argument in the resulting type constructor.
Inner constructors can still be defined, but at least one should accept
arguments in the same form as the default inner constructor (i.e. one
positional argument per field) in order to function correctly with the
keyword outer constructor.
│ Julia 1.1
│ Base.@kwdef for parametric structs, and structs with supertypes
│ requires at least Julia 1.1.
│ Julia 1.9
│ This macro is exported as of Julia 1.9.
julia> @kwdef struct Foo
a::Int = 1 # specified default
b::String # required keyword
ERROR: UndefKeywordError: keyword argument `b` not assigned