Skip to content

Commit 9edbf50

Browse files
committed
alias_doc
1 parent 0976234 commit 9edbf50

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/generate/register.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,24 @@ pub fn render(
8181
} else {
8282
return Err(anyhow!("Incorrect access of register {}", register.name));
8383
};
84-
let alias_doc =
85-
format!("{name} ({accs}) register accessor: an alias for `Reg<{regspec_ident}>`");
84+
85+
let mut alias_doc = format!(
86+
"{name} ({accs}) register accessor: {description}\n\n{}",
87+
api_docs(
88+
access.can_read(),
89+
access.can_write(),
90+
register.properties.reset_value.is_some(),
91+
&name_snake_case,
92+
false,
93+
register.read_action,
94+
)?
95+
);
96+
if name_snake_case != "cfg" {
97+
alias_doc += format!(
98+
"\n\nFor information about available fields see [`{name_snake_case}`] module"
99+
)
100+
.as_str();
101+
}
86102
let mut out = TokenStream::new();
87103
out.extend(quote! {
88104
#[doc = #alias_doc]
@@ -112,6 +128,7 @@ fn api_docs(
112128
can_write: bool,
113129
can_reset: bool,
114130
module: &Ident,
131+
inmodule: bool,
115132
read_action: Option<ReadAction>,
116133
) -> Result<String, std::fmt::Error> {
117134
fn method(s: &str) -> String {
@@ -123,8 +140,9 @@ fn api_docs(
123140
if can_read {
124141
write!(
125142
doc,
126-
"You can {} this register and get [`{module}::R`](R).",
127-
method("read")
143+
"You can {} this register and get [`{module}::R`]{}.",
144+
method("read"),
145+
if inmodule { "(R)" } else { "" },
128146
)?;
129147

130148
if let Some(action) = read_action {
@@ -148,21 +166,18 @@ fn api_docs(
148166
methods.push("write_with_zero");
149167
writeln!(
150168
doc,
151-
"You can {} this register using [`{module}::W`](W).<br>",
169+
"You can {} this register using [`{module}::W`]{}.<br>",
152170
methods
153171
.iter()
154172
.map(|m| method(m))
155173
.collect::<Vec<_>>()
156-
.join(", ")
174+
.join(", "),
175+
if inmodule { "(W)" } else { "" },
157176
)?;
158177
}
159178

160179
if can_read && can_write {
161-
writeln!(
162-
doc,
163-
"You can also {} this register using [`{module}::R`](R) and [`{module}::W`](W).<br>",
164-
method("modify")
165-
)?;
180+
writeln!(doc, "You can also {} this register.<br>", method("modify"),)?;
166181
}
167182

168183
doc.push_str("See [API](https://docs.rs/svd2rust/#read--modify--write-api).");
@@ -370,7 +385,8 @@ pub fn render_register_mod(
370385
can_write,
371386
can_reset,
372387
&name_snake_case,
373-
register.read_action
388+
true,
389+
register.read_action,
374390
)?
375391
);
376392

0 commit comments

Comments
 (0)