Suppose I have following code:
pub struct A<T>(T);
impl A<u8> {
/// See also [`A::inc`]
pub fn inc(&mut self) {
self.0 += 1;
}
}
impl A<u16> {
/// See also [`A::inc`]
pub fn inc(&mut self) {
self.0 += 1;
}
}
Both of the [`A::inc`]
references point to the same method. How do I make a reference to a specific method?
jofas
October 16, 2023, 2:03pm
2
Maybe you can provide the generic parameter like A::<u16>::inc
for example to make the docs reference the inc
implementation of A<u16>
? I'm on mobile and can't test myself if that's the right syntax.
Nope, that's the first thing I tried, along with placing them into separate modules.
vague
October 16, 2023, 2:19pm
4
Since the second inc generates struct.A.html#method.inc-1
in the link, so you can use [`A::<u16>::inc`](#method.inc-1)
to refer to it.
Update: or this by tagging an anchor if you're not sure about the enumeration
impl A<u16> {
/// <a name="A-u16-inc"></a>
///
/// See also [`A::<u16>::inc`](#A-u16-inc)
pub fn inc(&mut self) {
self.0 += 1;
}
}
Well... Yea, this works too, but I was hoping for something that works better across multiple modules and would complain if something is missing/renamed...
vague
October 16, 2023, 2:34pm
6
manpacket:
across multiple modules
If your desired anchor doesn't appear in the same webpage, it seems rustdoc supports relative path in the link
impl A<u16> {
/// <a name="A-u16-inc"></a>
pub fn inc(&mut self) {
self.0 += 1;
}
}
pub mod a {
/// See [`A::<u16>::inc`](../struct.A.html#A-u16-inc) -> This correctly leads to its place.
pub fn f() {}
}
Update: ../struct.A.html
can be replaced with Rust's path syntax, i.e. crate::A
and super::A
etc due to 1946-intra-rustdoc-links - The Rust RFC Book .
Very fragile I guess I should check tickets on rustdoc on this subject and make one if there's none.