fn main() { //declare buffer let buffer:String; //declare buffer_as_str &str let buffer_as_str:&'static str; //let buffer_as_str:&str; //set value of variable buffer buffer = "J. Cole, Nas, Jay-Z".to_string(); /* Get a reference to string variable */ buffer_as_str = buffer.as_str(); //pattern_formatted_as_str = &pattern_formatted[..]; //print buffer ( buffer ) println!( "buffer - variable name {} - variable value {}" , "buffer" , buffer ); //print buffer ( buffer_as_str ) println!( "buffer - variable name {} - variable value {}" , "buffer_as_str" , buffer_as_str ); }
Write, Run & Share Rust code online using OneCompiler's Rust online compiler for free. It's one of the robust, feature-rich online compilers for Rust language. Getting started with the OneCompiler's Rust editor is easy and fast. The editor shows sample boilerplate code when you choose language as Rust and start coding.