From d7bc531ee29f563822ed152c97adfc7d7bb0ef81 Mon Sep 17 00:00:00 2001 From: neuronull Date: Wed, 28 Jun 2023 12:21:45 -0600 Subject: [PATCH] chore(docs): add note about const strings (#17774) --- STYLE.md | 12 ++++++++++++ docs/DEVELOPING.md | 1 + 2 files changed, 13 insertions(+) diff --git a/STYLE.md b/STYLE.md index a1403ecb7fe4b..4e3e70818f708 100644 --- a/STYLE.md +++ b/STYLE.md @@ -24,6 +24,18 @@ As an additional note, `rustfmt` sometimes can fail to format code within macros to see such code that doesn't look like it's formatted correctly, you may need to manually tweak it if `rustfmt` cannot be persuaded to format it correctly for you. :) +### Const strings + +When re-typing the same raw string literal more than once, this can lead to typo +errors, especially when names ares similar. In general, when reasonable, it is +preferred to use [Compile-time constants](https://doc.rust-lang.org/std/keyword.const.html) +when dealing with non-dynamic strings. For example, when working with field names +for event metadata. + +As this has not always been a consistently enforced code style for the project, +please take the opportunity to update existing raw strings to use constants +when modifying existing code + ## Code Organization Code is primarily split into two main directories: `lib/` and `src/`. diff --git a/docs/DEVELOPING.md b/docs/DEVELOPING.md index 31a91795b7b75..0fa32c68d30c6 100644 --- a/docs/DEVELOPING.md +++ b/docs/DEVELOPING.md @@ -8,6 +8,7 @@ - [Makefile](#makefile) - [Code style](#code-style) - [Logging style](#logging-style) + - [Panics](#panics) - [Feature flags](#feature-flags) - [Dependencies](#dependencies) - [Guidelines](#guidelines)