-
Understanding String, &str etc코딩Coding/★Rust★기초★Syntax 2022. 2. 21. 15:10728x90
Understanding String, &str etc
Hi,
I don't quite understand how strings work.
if I have a struct with a Struct
struct User {
name:String
}
then I can instantiate it as follows
let user = User {
name: "John".to_string()
}
If I leave out the to\_string() it won't compile
However if I do it this way and then do this:
format!("Name is {:?}", user.name);
Then the resulting string has escaped quotes like this:
"Name is \"John\""
What is going on here?
What is the difference between String and &str in Rust?
https://youtu.be/n7-vKRLw3zg
반응형'코딩Coding > ★Rust★기초★Syntax' 카테고리의 다른 글
Rust]<What is a function signature and type? (0) 2022.02.23 Rust 27분 짜리 간단한 강의- Tim McNamara- Rist Linz (0) 2022.02.23 Rust Async- How to build an Async Router in Rust!!- Jeremy Chone (0) 2022.02.22 Rust] 16진수 -> 10진수 숫자 출력하는 방법 (0) 2022.02.22 I'm still having difficulty understanding Iterator and IntoIter (0) 2022.02.21 Rust vs. C Language (Size of val)byte와 함께 정리 (0) 2022.02.19 impl<T> !Sync for Cell<T>where[not sync(=synchronize)] (0) 2022.02.19 Rust data types (0) 2022.02.17