rustrust string const
A Rust String const
is a type of constant that is used to store a string value. It is declared using the const
keyword and is immutable, meaning it cannot be changed once declared.
Example code
const MY_STRING: &str = "Hello World!";
Output example
Hello World!
Code explanation
const
: The keyword used to declare a constant.MY_STRING
: The name of the constant.&str
: The type of the constant.&str
is a string slice, which is a reference to a string value."Hello World!"
: The value of the constant.
Helpful links
More of Rust
- How to match whitespace with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to split a string with Rust regex?
- How to iterate over a Rust slice with an index?
- How to use negation in Rust regex?
- How to use regex captures in Rust?
- Regex example to match multiline string in Rust?
- How to get a capture group using Rust regex?
- How to use modifiers in a Rust regex?
- How to create a HashMap of structs in Rust?
See more codes...