Skip to content

Commit 91976c2

Browse files
IanButterworthKristofferC
authored andcommitted
document mutable struct const fields (#55203)
Introduced in #43305 (cherry picked from commit 6b08e80)
1 parent 35f56b1 commit 91976c2

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

base/docs/basedocs.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,20 @@ kw"struct"
14191419
mutable struct
14201420
14211421
`mutable struct` is similar to [`struct`](@ref), but additionally allows the
1422-
fields of the type to be set after construction. See the manual section on
1423-
[Composite Types](@ref) for more information.
1422+
fields of the type to be set after construction.
1423+
1424+
Individual fields of a mutable struct can be marked as `const` to make them immutable:
1425+
1426+
```julia
1427+
mutable struct Baz
1428+
a::Int
1429+
const b::Float64
1430+
end
1431+
```
1432+
!!! compat "Julia 1.8"
1433+
The `const` keyword for fields of mutable structs requires at least Julia 1.8.
1434+
1435+
See the manual section on [Composite Types](@ref) for more information.
14241436
"""
14251437
kw"mutable struct"
14261438

0 commit comments

Comments
 (0)