Add guidance about linking to external crates #186
Replies: 12 comments
-
This is worth prioritizing, as we are taking the risk of making poor decisions in the documentation process. In emphasis:
This is true, but it does not work once uploaded to docs.rs. Broken documentation links ensue to those reading the docs online. But at the same time, I don't feel very eager to hardcode an absolute link to docs.rs, since not all crates have adopted this service. Perhaps some tooling improvements are needed before we think about guidance? |
Beta Was this translation helpful? Give feedback.
-
This kind of advice would also be great for crates that use |
Beta Was this translation helpful? Give feedback.
-
I would also like to see this. I've been using |
Beta Was this translation helpful? Give feedback.
-
What is the preferred way to link to a
I think item 1 is only for use inside std lib docs, where String would be a relative crate? |
Beta Was this translation helpful? Give feedback.
-
As a document author, I would like to specify intent and let the tool figure out the links. Perhaps a custom scheme (e.g Would the complexity of the url format ar docs.rs / doc.rust-lang.org be too difficult to use in this simple of a format e.g. as the URLs include extra keywords.
Notes:
|
Beta Was this translation helpful? Give feedback.
-
I think this is fixed by rust-lang/rust#74430, which will be stable tomorrow in 1.48. The documentation should say to use intra-doc links for your dependencies. Note that this doesn't work for crates you don't depend on (rust-lang/rust#74481), in that case I think it does make sense to recommend docs.rs. |
Beta Was this translation helpful? Give feedback.
-
I don't think there's a great solution for this in general, since intra-doc links use rust scopes and crates don't know their own names (so |
Beta Was this translation helpful? Give feedback.
-
@jyn514 the main problem we're hitting this at the moment is documenting I've tried to use Another problem with docs.rs that very often crates in closed codebases are not published there. |
Beta Was this translation helpful? Give feedback.
-
If you add a doc comment to the re-export in //- foo-codegen/src/lib.rs
#[proc_macro_derive]
pub fn Bar(/*...*/) -> /*...*/ { /*...*/ }
//- foo/src/lib.rs
/// Doc comment containing [`foo::Bar`].
pub use foo_codegen::Bar; |
Beta Was this translation helpful? Give feedback.
-
I spent a long time getting the scoping for this to work 😅 I don't remember if it's in 1.48 but it will definitely be in 1.49. |
Beta Was this translation helpful? Give feedback.
-
@bjorn3 @jyn514 nice to know, thanks! But it still would be nice to have an ability to intra-doc-link dev-dependenices in docs. As code generation logic happens to be quite untrivial in many situations, we usually write docs to it, which explain and guide through the implementation. Those are private docs, but having an ability in them to refer the crate (codegen is implemented for) would be nice. |
Beta Was this translation helpful? Give feedback.
-
See the discussion in rust-lang/rust#74481, this requires fundamental changes to how cargo compiles crates. I agree it would be nice to have but it's not clear how. |
Beta Was this translation helpful? Give feedback.
-
The Documentation page should add information about linking to external types/crates. Right now we have the following section:
This talks about linking to your own types, but what about for types/functions/etc. in other crates? What is the best practice for those? What does a link need to look like so docs.rs will resolve the link correctly? Most people use docs.rs to host their docs, so it needs to work well there.
Should people use absolute links? For example:
If so, what should the version be? I put
*
in the link above but another valid choice would be the current version my crate is using. Is there a way to do this without having to update version numbers all the time whenever I upgrade a dependency? What (if anything) does rustdoc provide in this regard?Absolute links are a little less convenient when developing locally. I think many crate authors actually use relative links like the following because this works when you run
cargo doc
:Information about all of this would be a great addition to the guidelines because I think crate authors think about this stuff and if we're going to ask them to "Link all the things" we should at provide enough guidance for them to do that.
Beta Was this translation helpful? Give feedback.
All reactions