I'm looking for a way to manage constant strings in a Rust project. The hope is to manage my strings from a single file and avoid having the same string literals all over the place in the project.
Would the "Rust" way of doing this be to create something like constants.rs
which would include my strings, something like...
pub const COMMONSTRING: &str = "common string value";
pub const ANOTHERCOMMONSTRING: &str = "another common string value";
...and then use mod constants;
in the subsequent locations where they are needed? The idea is that I will be using these constant strings later in format!()
calls with various other string literals. This is the approach I have been taking so far and it seems to be working, i.e.
mod constants;
...
let path_str = &format!("./{}", constants::PATHSTRING);
Being new to Rust I wanted to make sure this seemed like a logical way to handle this, any feedback would be much appreciated!