String Literal
String Literal or &str are called ‘string slices’, which always point to a legitimate UTF-8 sequence. It is used when we know the value of a string at compile time. They are a set of characters and static by default.
Example 1: Declaring string literals.
Rust
fn main() { let website:&str= "w3wiki.org" ; let language:&str = "RUST" ; println!( "Website is {}" ,website); println!( "Language is {}" ,language); } |
Output:
Website is w3wiki.org
Language is RUST
Rust – Strings
String data type is a very important part of any programming language. Rust handles strings a bit differently from other languages.
The String data type in Rust is of two types:
- String Literal (&str)
- String Object (String)
Contact Us