Skip to content

Commit 6b08e80

Browse files
document mutable struct const fields (#55203)
Introduced in #43305
1 parent b75c133 commit 6b08e80

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
@@ -1451,8 +1451,20 @@ kw"struct"
14511451
mutable struct
14521452
14531453
`mutable struct` is similar to [`struct`](@ref), but additionally allows the
1454-
fields of the type to be set after construction. See the manual section on
1455-
[Composite Types](@ref) for more information.
1454+
fields of the type to be set after construction.
1455+
1456+
Individual fields of a mutable struct can be marked as `const` to make them immutable:
1457+
1458+
```julia
1459+
mutable struct Baz
1460+
a::Int
1461+
const b::Float64
1462+
end
1463+
```
1464+
!!! compat "Julia 1.8"
1465+
The `const` keyword for fields of mutable structs requires at least Julia 1.8.
1466+
1467+
See the manual section on [Composite Types](@ref) for more information.
14561468
"""
14571469
kw"mutable struct"
14581470

0 commit comments

Comments
 (0)