Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 240 characters in body
Source Link
Shepmaster
  • 439.3k
  • 116
  • 1.3k
  • 1.5k
let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program. No heap memory is allocated; the data for the string lives within the binary of the program itself.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before 1.9.0 (specifically because of this commit), this is slower than directly converting using String::from. In version 1.9.0 and after, calling .to_string() on a string literal is the same speed as String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program. No heap memory is allocated; the data for the string lives within the binary of the program itself.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before 1.9.0 (specifically because of this commit), this is slower than directly converting using String::from. In version 1.9.0 and after, calling .to_string() on a string literal is the same speed as String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

added 109 characters in body
Source Link
Shepmaster
  • 439.3k
  • 116
  • 1.3k
  • 1.5k
let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

let hello1 = "Hello, world!"; 

This creates a string slice (&str). Specifically, a &'static str, a string slice that lives for the entire duration of the program.

let hello2 = "Hello, world!".to_string(); 

This uses the formatting machinery to format any type that implements Display, creating an owned, allocated string (String). In versions of Rust before this commit, this is slower than directly converting using String::from.

let hello3 = String::from("Hello, world!"); 

This converts a string slice to an owned, allocated string (String) in an efficient manner.

let hello4 = "hello, world!".to_owned(); 

The same as String::from.

See also:

Source Link
Shepmaster
  • 439.3k
  • 116
  • 1.3k
  • 1.5k
Loading