There is a ALPHABET
for arithmetic, it's const and used in a lot of functions. I want make the ALPHABET
global, static, and const. Some functions need the ALPHABET
type as &String
, but str.to_string()
function will happen once memory copy. this function is called frequently, so it's not good.
The used function is a library, can't change it.
static ALPHABET: &str = "xxxxxxxxxxxxxxxxxxxxxxx";
fn some1(value: &String, alphabet: &String) -> String {
xxxx
}
fn main() {
some1("test", ALPHABET); // Can't build
some1("test", &ALPHABET.to_string()); // OK, but will happend memory copy.
}
How use the ALPHABET
without to_string()
function?