How to force comments at end of enum item

hi, I want to write some comments in the same line with enum item, like this

but after rustfmt, it always move my comments to a new line . Is there possible to tell rustfmt to keep my comments at the same line of enum item. (I tried "//!", "//<", but still not work)

The standard way to write this comment is above the enum variant like so:

pub(crate) enum FileErr {
    /// File name is a valid path.

This can then be interpreted as the doc attribute of the InvalidFileName enum variant. (see this section from the rust reference).

There isn't a way (that I know of) to write a comment that is a doc attribute after the enum-variant/item/whatever.

If you just want a way to make rustfmt to format a regular comment like that, I don't really know because I don't use it, but might be just the configuration for maximum line length.


I'm confused. Is that thing invalid, as the name suggests, or valid as the comment claims?


:rofl: :rofl: :rofl: the comment is used to confuse users


If the thing was named meaningfully there would be no need for any comment.

Maybe the filename is Path::new("Invalid").

Building on @dupdrop's comment, you can add #![deny(missing_docs)] to the top of your crate to force all public items (functions, structs, enums, enum variants, etc.) to be documented (the /// comments). Similarly, if you only want to enforce the missing_docs lint for certain items, add a #[deny(missing_docs)] attribute above them.

As a nice side effect, cargo doc will pick up these /// comments and use them to generate pretty HTML documentation. It's similar to tools like doxygen, but I feel like rustdoc is a lot nicer to use and generates more usable docs.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.