-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: add style guide Signed-off-by: Ruihang Xia <[email protected]> * add comments section Signed-off-by: Ruihang Xia <[email protected]> * add comment order Signed-off-by: Ruihang Xia <[email protected]> * about error handling Signed-off-by: Ruihang Xia <[email protected]> * about error logging Signed-off-by: Ruihang Xia <[email protected]> --------- Signed-off-by: Ruihang Xia <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# GreptimeDB Style Guide | ||
|
||
This style guide is intended to help contributors to GreptimeDB write code that is consistent with the rest of the codebase. It is a living document and will be updated as the codebase evolves. | ||
|
||
It's mainly an complement to the [Rust Style Guide](https://pingcap.github.io/style-guide/rust/). | ||
|
||
## Table of Contents | ||
|
||
- Formatting | ||
- Modules | ||
- Comments | ||
|
||
## Formatting | ||
|
||
- Place all `mod` declaration before any `use`. | ||
- Use `unimplemented!()` instead of `todo!()` for things that aren't likely to be implemented. | ||
- Add an empty line before and after declaration blocks. | ||
- Place comment before attributes (`#[]`) and derive (`#[derive]`). | ||
|
||
## Modules | ||
|
||
- Use the file with same name instead of `mod.rs` to define a module. E.g.: | ||
|
||
``` | ||
. | ||
├── cache | ||
│ ├── cache_size.rs | ||
│ └── write_cache.rs | ||
└── cache.rs | ||
``` | ||
|
||
## Comments | ||
|
||
- Add comments for public functions and structs. | ||
- Prefer document comment (`///`) over normal comment (`//`) for structs, fields, functions etc. | ||
- Add link (`[]`) to struct, method, or any other reference. And make sure that link works. | ||
|
||
## Error handling | ||
|
||
- Define a custom error type for the module if needed. | ||
- Prefer `with_context()` over `context()` when allocation is needed to construct an error. | ||
- Use `error!()` or `warn!()` macros in the `common_telemetry` crate to log errors. E.g.: | ||
|
||
```rust | ||
error!(e; "Failed to do something"); | ||
``` |