-
Rust연습] cow_빨라서 최고borrow에서 적극 활용하자코딩Coding/Rust연습 2022. 4. 19. 22:19728x90
~/Documents/Project/Github/rust_project/training_rustacean_rust/src/main.rs.html 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
반응형'코딩Coding > Rust연습' 카테고리의 다른 글
Rust연습)그래프 그리기 + 움직이는 별 표현하기(움직이는 gif만들기) (0) 2022.06.15 Rust연습] tuple연습❤️ & ndarray ❤️연습 (0) 2022.06.02 Rust연습] Cow__120 Easy Rust in Korean: to_mut with Cow (0) 2022.04.19 Rust연습]Cow part2 (0) 2022.04.19 rust연습]vec벡터 끼리 합치기 + vec + vec append (0) 2022.04.18 rust연습]u8_sting_stack저장하기bytes() / std::str (0) 2022.04.18 rust연습]10진수 숫자 16진수로 알아보는 방법& 16진수를 10진수 숫자로 알아보는 방법 (0) 2022.04.17 rust연습] pi(𝜋)파이 1억자리까지 계산 하기 (0) 2022.04.16