Skip to content

Commit d3aa174

Browse files
committed
rustdoc: Add definition of iface docs
1 parent 9db1d16 commit d3aa174

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/rustdoc/doc.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ enum itemtag {
1111
consttag(constdoc),
1212
fntag(fndoc),
1313
enumtag(enumdoc),
14-
restag(resdoc)
14+
restag(resdoc),
15+
ifacetag(ifacedoc)
1516
}
1617

1718
type moddoc = {
@@ -77,6 +78,24 @@ type resdoc = {
7778
sig: option<str>
7879
};
7980

81+
type ifacedoc = {
82+
id: ast_id,
83+
name: str,
84+
brief: option<str>,
85+
desc: option<str>,
86+
methods: [methoddoc]
87+
};
88+
89+
type methoddoc = {
90+
name: str,
91+
brief: option<str>,
92+
desc: option<str>,
93+
args: [argdoc],
94+
return: retdoc,
95+
failure: option<str>,
96+
sig: option<str>
97+
};
98+
8099
impl util for moddoc {
81100

82101
fn mods() -> [moddoc] {
@@ -123,6 +142,15 @@ impl util for moddoc {
123142
}
124143
}
125144
}
145+
146+
fn ifaces() -> [ifacedoc] {
147+
vec::filter_map(*self.items) {|itemtag|
148+
alt itemtag {
149+
ifacetag(ifacedoc) { some(ifacedoc) }
150+
_ { none }
151+
}
152+
}
153+
}
126154
}
127155

128156
impl util for itemtag {
@@ -133,6 +161,7 @@ impl util for itemtag {
133161
doc::consttag({name, _}) { name }
134162
doc::enumtag({name, _}) { name }
135163
doc::restag({name, _}) { name }
164+
doc::ifacetag({name, _}) { name }
136165
}
137166
}
138167
}

src/rustdoc/fold.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default_seq_fold_fn;
1010
export default_seq_fold_const;
1111
export default_seq_fold_enum;
1212
export default_seq_fold_res;
13+
export default_seq_fold_iface;
1314

1415
enum fold<T> = t<T>;
1516

@@ -19,6 +20,7 @@ type fold_fn<T> = fn~(fold: fold<T>, doc: doc::fndoc) -> doc::fndoc;
1920
type fold_const<T> = fn~(fold: fold<T>, doc: doc::constdoc) -> doc::constdoc;
2021
type fold_enum<T> = fn~(fold: fold<T>, doc: doc::enumdoc) -> doc::enumdoc;
2122
type fold_res<T> = fn~(fold: fold<T>, doc: doc::resdoc) -> doc::resdoc;
23+
type fold_iface<T> = fn~(fold: fold<T>, doc: doc::ifacedoc) -> doc::ifacedoc;
2224

2325
type t<T> = {
2426
ctxt: T,
@@ -27,7 +29,8 @@ type t<T> = {
2729
fold_fn: fold_fn<T>,
2830
fold_const: fold_const<T>,
2931
fold_enum: fold_enum<T>,
30-
fold_res: fold_res<T>
32+
fold_res: fold_res<T>,
33+
fold_iface: fold_iface<T>
3134
};
3235

3336

@@ -40,7 +43,8 @@ fn mk_fold<T:copy>(
4043
fold_fn: fold_fn<T>,
4144
fold_const: fold_const<T>,
4245
fold_enum: fold_enum<T>,
43-
fold_res: fold_res<T>
46+
fold_res: fold_res<T>,
47+
fold_iface: fold_iface<T>
4448
) -> fold<T> {
4549
fold({
4650
ctxt: ctxt,
@@ -49,7 +53,8 @@ fn mk_fold<T:copy>(
4953
fold_fn: fold_fn,
5054
fold_const: fold_const,
5155
fold_enum: fold_enum,
52-
fold_res: fold_res
56+
fold_res: fold_res,
57+
fold_iface: fold_iface
5358
})
5459
}
5560

@@ -61,7 +66,8 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
6166
{|f, d| default_seq_fold_fn(f, d)},
6267
{|f, d| default_seq_fold_const(f, d)},
6368
{|f, d| default_seq_fold_enum(f, d)},
64-
{|f, d| default_seq_fold_res(f, d)}
69+
{|f, d| default_seq_fold_res(f, d)},
70+
{|f, d| default_seq_fold_iface(f, d)}
6571
)
6672
}
6773

@@ -96,6 +102,9 @@ fn default_seq_fold_mod<T>(
96102
doc::restag(resdoc) {
97103
doc::restag(fold.fold_res(fold, resdoc))
98104
}
105+
doc::ifacetag(ifacedoc) {
106+
doc::ifacetag(fold.fold_iface(fold, ifacedoc))
107+
}
99108
}
100109
}
101110
with doc
@@ -130,6 +139,13 @@ fn default_seq_fold_res<T>(
130139
doc
131140
}
132141

142+
fn default_seq_fold_iface<T>(
143+
_fold: fold<T>,
144+
doc: doc::ifacedoc
145+
) -> doc::ifacedoc {
146+
doc
147+
}
148+
133149
#[test]
134150
fn default_fold_should_produce_same_doc() {
135151
let source = "mod a { fn b() { } mod c { fn d() { } } }";

0 commit comments

Comments
 (0)