Skip to content

Commit 43cdc58

Browse files
IanButterworthKristofferC
authored andcommitted
document mutable struct const fields (#55203)
Introduced in #43305 (cherry picked from commit 6b08e80)
1 parent 6225d9a commit 43cdc58

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

base/docs/basedocs.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,20 @@ kw"struct"
14001400
mutable struct
14011401
14021402
`mutable struct` is similar to [`struct`](@ref), but additionally allows the
1403-
fields of the type to be set after construction. See the manual section on
1404-
[Composite Types](@ref) for more information.
1403+
fields of the type to be set after construction.
1404+
1405+
Individual fields of a mutable struct can be marked as `const` to make them immutable:
1406+
1407+
```julia
1408+
mutable struct Baz
1409+
a::Int
1410+
const b::Float64
1411+
end
1412+
```
1413+
!!! compat "Julia 1.8"
1414+
The `const` keyword for fields of mutable structs requires at least Julia 1.8.
1415+
1416+
See the manual section on [Composite Types](@ref) for more information.
14051417
"""
14061418
kw"mutable struct"
14071419

0 commit comments

Comments
 (0)