Skip to content

Commit 5280a5d

Browse files
committed
Improve documentation
1 parent c57a1f5 commit 5280a5d

File tree

2 files changed

+93
-9
lines changed

2 files changed

+93
-9
lines changed

docs/src/index.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ CurrentModule = RedefStructs
66

77
Documentation for [RedefStructs.jl](https://github.com/FedericoStra/RedefStructs.jl).
88

9-
This package provides the macro [`@redef`](@ref), which allows to create `struct`ures which are redefinable.
9+
This package provides the macros [`@redef`](@ref) and [`@redef_print`](@ref),
10+
which allow to create `struct`ures which are redefinable.
1011

11-
## Example
12+
```@contents
13+
Depth = 3
14+
```
15+
16+
## Examples
17+
18+
Using [`@redef`](@ref):
1219

1320
```jldoctest
1421
julia> using RedefStructs
@@ -28,11 +35,41 @@ julia> S(42).n
2835
42
2936
```
3037

38+
Using [`@redef_print`](@ref):
39+
40+
```jldoctest
41+
julia> using RedefStructs
42+
43+
julia> @redef_print struct S
44+
s::String
45+
end
46+
47+
julia> S("Hello").s
48+
"Hello"
49+
50+
julia> @redef_print mutable struct S
51+
n::Int
52+
end
53+
54+
julia> S(42).n
55+
42
56+
```
57+
3158
## Library
3259

3360
```@index
3461
```
3562

63+
### Public
64+
65+
```@autodocs
66+
Modules = [RedefStructs]
67+
Private = false
68+
```
69+
70+
### Private
71+
3672
```@autodocs
3773
Modules = [RedefStructs]
74+
Public = false
3875
```

src/RedefStructs.jl

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ export @redef, @redef_print
99
1010
Define a structure in a manner that allows redefinitions.
1111
12+
Behind the scenes, this creates a "secret" structure with
13+
[`gensym`](https://docs.julialang.org/en/v1/base/base/#Base.gensym)
14+
and assigns `S` to its name.
15+
16+
See also [`@redef_print`](@ref).
17+
1218
# Examples
1319
14-
```
15-
@redef struct S
16-
s::String
17-
end
20+
```jldoctest
21+
julia> using RedefStructs
1822
19-
@redef mutable struct S
20-
n::Int
21-
end
23+
julia> @redef struct S
24+
s::String
25+
end
26+
27+
julia> S("Hello").s
28+
"Hello"
29+
30+
julia> @redef mutable struct S
31+
n::Int
32+
end
33+
34+
julia> S(42).n
35+
42
2236
```
2337
"""
2438
macro redef(struct_def)
@@ -34,6 +48,39 @@ macro redef(struct_def)
3448
end)
3549
end
3650

51+
@doc """
52+
@redef [mutable] struct S [<: A]
53+
...
54+
end
55+
56+
Define a structure in a manner that allows redefinitions.
57+
58+
Behind the scenes, this creates a "secret" structure with
59+
[`gensym`](https://docs.julialang.org/en/v1/base/base/#Base.gensym)
60+
and defines a specialized method of `Base.show_datatype` which shows `S`.
61+
62+
See also [`@redef`](@ref).
63+
64+
# Examples
65+
66+
```jldoctest
67+
julia> using RedefStructs
68+
69+
julia> @redef_print struct S
70+
s::String
71+
end
72+
73+
julia> S("Hello").s
74+
"Hello"
75+
76+
julia> @redef_print mutable struct S
77+
n::Int
78+
end
79+
80+
julia> S(42).n
81+
42
82+
```
83+
"""
3784
macro redef_print(struct_def)
3885
name = struct_def_name(struct_def)
3986
real_name = gensym(name)

0 commit comments

Comments
 (0)