mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-06 23:06:49 +02:00
rust: improve explanation of string slices
This commit is contained in:
@@ -92,10 +92,8 @@ fn main() {
|
|||||||
let s: String = "hello world".to_string();
|
let s: String = "hello world".to_string();
|
||||||
|
|
||||||
// A string slice – an immutable view into another string
|
// A string slice – an immutable view into another string
|
||||||
// This is basically an immutable pair of pointers to a string – it doesn’t
|
// The string buffer can be statically allocated like in a string literal
|
||||||
// actually contain the contents of a string, just a pointer to
|
// or contained in another object (in this case, `s`)
|
||||||
// the begin and a pointer to the end of a string buffer,
|
|
||||||
// statically allocated or contained in another object (in this case, `s`)
|
|
||||||
let s_slice: &str = &s;
|
let s_slice: &str = &s;
|
||||||
|
|
||||||
println!("{} {}", s, s_slice); // hello world hello world
|
println!("{} {}", s, s_slice); // hello world hello world
|
||||||
|
Reference in New Issue
Block a user