mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 20:49:41 +00:00
fix: use map func to avoid copy of string
This commit is contained in:
@ -53,7 +53,7 @@ fn main() {
|
||||
check_size([0u8; 767]);
|
||||
check_size([0i32; 191]);
|
||||
check_size(["hello你好"; 47]); // &str is a string reference, containing a pointer and string length in it, so it takes two word long, in x86-64, 1 word = 8 bytes
|
||||
check_size(["hello你好".to_string(); 31]); // String is a smart pointer struct, it has three fields: pointer, length and capacity, each takes 8 bytes
|
||||
check_size([(); 31].map(|_| "hello你好".to_string())); // String is a smart pointer struct, it has three fields: pointer, length and capacity, each takes 8 bytes
|
||||
check_size(['中'; 191]); // A char takes 4 bytes in Rust
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user