let hello1 = "Hello, world!";
let hello2 = "Hello, world!".to_string();
let hello3 = String::from("Hello, world!");
相关问题
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Share Arc between closures
- Converting a string array to a byte array
- Function references: expected bound lifetime param
相关文章
- How can I convert a f64 to f32 and get the closest
- JSP String formatting Truncate
- What is a good way of cleaning up after a unit tes
- Selecting only the first few characters in a strin
- Python: print in two columns
- extending c++ string member functions
- Google app engine datastore string encoding proble
- How can I unpack (destructure) elements from a vec
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.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 usingString::from
. In version 1.9.0 and after, calling.to_string()
on a string literal is the same speed asString::from
.This converts a string slice to an owned, allocated string (
String
) in an efficient manner.The same as
String::from
.See also: