Comment blocks to delimit source code into areas of similar function


#1

I’ve started playing with Rust recently and I’m writing a toy HTTP parser / server library as a learning exercise.

As a C programmer, I’m used to the idea of starting every source file by copying a template. The template would look something like:

/*****************************************************
*
* Foo Project
*
* Copyright (c) 2014 theJPster (www.thejpster.org.uk)
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************/

/**************************************************
* Includes
***************************************************/

#include "util/util.h"
#include "../template.h"

/**************************************************
* Defines
***************************************************/

/* None */

/**************************************************
* Data Types
**************************************************/

/* None */

/**************************************************
* Function Prototypes
**************************************************/

/* None */

/**************************************************
* Public Data
**************************************************/

/* None */

/**************************************************
* Private Data
**************************************************/

/* None */

/**************************************************
* Public Functions
***************************************************/

/* None */

/**************************************************
* Private Functions
***************************************************/

/* None */

/**************************************************
* End of file
***************************************************/

I tried to put similar code blocks into my rust source, and they made rustfmt sad. It turned the /* */ comments into //, then // into ///, and then complained that the /// wasn’t attached to anything.

Is there a comment style I can use for these sorts of blocks that rustfmt will tolerate?


#2

Well, there are two problems. The first is that /** starts a doc comment, attached to the next item in the file. If you wanted a doc comment attached to the containing module, you need to start with /*!. If you didn’t want a doc comment at all, then start with /* *.

The second problem is that, last I checked, rustfmt has a pathological hatred of block comments. It’s a part of why I gave up on using it.

The simple solution is to not use rustfmt. The less simple solution is to not use block comments, anywhere, for any purpose, and use horrible line comments instead. Nassssty line commentses. We hates them! Gollum!


#3

There is normalize_comments option in Rustfmt. I haven’t tried it myself though.


#4

Good call. This seems to work, but it’s going to take my eyes a little time to adjust…

// ****************************************************************************
//
// Public Types
//
// ****************************************************************************