Types
The docstrings for these abbreviations are in the reference.
"""
[`TYPEDEF`](@ref) prints the type's header:
$(TYPEDEF)
---
[`FIELDS`](@ref) lists the fields, with the docstring of each field that has one:
$(FIELDS)
---
[`TYPEDFIELDS`](@ref) adds the field types:
$(TYPEDFIELDS)
"""
struct Foobar{T <: AbstractString}
"Docstring for the `x` field."
x :: Nothing
y :: T # y has no docstring
"Docstring for the `z` field."
z :: Vector{T}
end
"""
[`SIGNATURES`](@ref) lists the constructors that the struct definition creates:
$(SIGNATURES)
---
A field given a default with `Base.@kwdef` shows its default in [`FIELDS`](@ref) and
[`TYPEDFIELDS`](@ref):
$(TYPEDFIELDS)
"""
Base.@kwdef struct Settings
"Seconds to wait before giving up."
timeout::Float64 = 30.0
retries::Int = 3
name::String
end
"""
An interface for shapes. [`SUBTYPES`](@ref) lists the types that implement it:
$(SUBTYPES)
"""
abstract type Shape end
"A circle."
struct Circle <: Shape end
"A square."
struct Square <: Shape end
The docstring renders as:
Examples.Foobar — Type
TYPEDEF prints the type's header:
struct Foobar{T<:AbstractString}FIELDS lists the fields, with the docstring of each field that has one:
x: Docstring for thexfield.yz: Docstring for thezfield.
TYPEDFIELDS adds the field types:
x::Nothing: Docstring for thexfield.y::AbstractStringz::Vector{T} where T<:AbstractString: Docstring for thezfield.
Examples.Settings — Type
SIGNATURES lists the constructors that the struct definition creates:
Settings(; timeout, retries, name)
Settings(timeout, retries, name)A field given a default with Base.@kwdef shows its default in FIELDS and TYPEDFIELDS:
timeout::Float64 = 30.0: Seconds to wait before giving up.retries::Int64 = 3name::String
Examples.Shape — Type
Examples.Circle — Type
A circle.
Examples.Square — Type
A square.
FIELDS and TYPEDFIELDS work only on the fields of a type. For function arguments, see Function arguments.