简体   繁体   中英

How do you document a Rust struct/enum in one documentation block before the struct?

How do you document a Rust struct or enum in one documentation block before the type, so as to avoid polluting the contents with confusing mess?

This is what I do at the moment, which is really terrible.

/// Enumerates the possible jobblers in thingy paradigm.
enum MyEnum
{
  /// Something is a blue exchange doodad thingy thing. 
  EnumValue1,
  /// Something is meld mould mild mote.
  EnumValueTheSecond,
  /// Vivamus arcu mauris, interdum nec ultricies vitae, sagittis sit.
  EnumValueGamma,
}

What I want is the style I would write it in Doxygen, which is clean and easy to read:

/** \enum MyEnum
 *     Enumerates the possible jobblers in thingy paradigm.
 *  \var  MyEnum::EnumValue1
 *     Something is a blue exchange doodad thingy thing. 
 *  \var  MyEnum::EnumValueTheSecond
 *     Something is meld mould mild mote.
 *  \var  MyEnum::EnumValueGamma
 *     Vivamus arcu mauris, interdum nec ultricies vitae, sagittis sit.
 */
enum MyEnum
{
  EnumValue1,
  EnumValueTheSecond,
  EnumValueGamma,
};

This is what I do at the moment, which is really terrible.

I guess the beauty is in the eye of the beholder? It looks fine to me, the reader of the code gets to see the documentation for the corresponding item in the same place, which makes sense.

What I want is the style I would write it in Doxygen, which is clean and easy to read:

Again I guess beauty is in the eye of the beholder as I think this looks like garbage on fire, but AFAIK rustdoc does not support this (a doc-comment is just commonmark with limited extension ), so you could:

How about documenting the enum values after the enum values like:

/// Enumerates the possible jobblers in thingy paradigm.
enum MyEnum
{
  EnumValue1, ///< Something is a blue exchange doodad thingy thing.
  EnumValueTheSecond, ///< Something is meld mould mild mote.
  EnumValueGamma, ///< Vivamus arcu mauris, interdum nec ultricies vitae, sagittis sit.
}

Result with doxygen 1.9.2:

在此处输入图像描述

Note from the discussion in the comment: the given example works in doxygen but not in cargo doc . Doxygen does not support Rust so the code first has to be translated into something that doxygen does understand (eg by means of a doxygen filter). The given example in the question looks quite similar to C / C++ code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM