PingCAP Style Guide

Guide to writing idiomatic code at PingCAP and in the TiKV project.


Project maintained by pingcap Hosted on GitHub Pages — Theme by mattgraham

Rust

Contents

Introduction

You use Rustfmt and Clippy. You should use Rustfmt with no customisation (rustfmt.toml file). You should use Clippy with the same set of disabled lints as TiKV. The easiest way to do that with TiKV is to use make clippy rather than cargo clippy.

Idiomatic Rust programming changed with the 2018 edition. For example, how imports are written and which lifetimes can be elided. You should always use Rust 2018, and should use the modern idioms (such as avoiding extern crate, importing macros using use). Be aware when reading older code that it may be from pre-2018 edition.

When writing Rust where there are competing conventions, e.g., with FFI and C or interacting with protocol buffers, stick to the Rust conventions rather than the domain conventions. E.g., types which are wrappers around C types should have CamelCase names even if the underlying types have snake_case names (though the bindings themselves will have the C names).

Further reading

The following resources were useful in making this guide, there is often more detail than could be accommodated here.

Open questions

FIXME: address these