코딩Coding/Rust연습
Rust연습] cow_빨라서 최고borrow에서 적극 활용하자
내인생PLUS
2022. 4. 19. 22:19
728x90
1 use std::borrow::Cow; 2 3 #[derive(Debug)] 4 struct User<'a> { 5 name: Cow<'a, str>, 6 } 7 8 fn main() { 9 let name_1 = "User 1"; 10 let name_2 = "User 2".to_string(); 11 12 let user_1 = User { 13 name: name_1.into(), 14 }; 15 16 let user_2 = User { 17 name: name_2.into(), 18 }; 19 20 println!("User 1 is {user_1:?} and User 2 is {user_2:?}"); 21 }
결과
warning: `training_rustacean_rust` (bin "training_rustacean_rust") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.08s
Running `target/debug/training_rustacean_rust`
User 1 is User { name: "User 1" } and User 2 is User { name: "User 2" }
https://www.youtube.com/watch?v=1UrSBfjZaU0&t=9s
반응형