코딩Coding/Rust연습
-
Rust – Fibonacci using Recursion and Iteration코딩Coding/Rust연습 2022. 6. 26. 05:25
Rust – Fibonacci using Recursion and Iteration use std::time::{Duration, Instant, SystemTime}; fn fibonacci_recusive(n: i64) -> i64 { if n i64 { let mut first_number: i64 = 0; let mut second_number: i64 = 0; let mut current_number: i64 = 1; let mut i: i64 = 1; while i < n { first_n..
-
Rust연습❤️) Collect & Vec 조합 Closure활용코딩Coding/Rust연습 2022. 6. 23. 17:51
fn main() { let my_vec = ((-10..=10).map(|x| (x, x* x))).collect::(); println!("{my_vec:?}"); } 결과 : Standard Error Compiling playground v0.0.1 (/playground) Finished dev [unoptimized + debuginfo] target(s) in 4.09s Running `target/debug/playground` Standard Output [(-10, 100), (-9, 81), (-8, 64), (-7, 49), (-6, 36), (-5, 25), (-4, 16), (-3, 9), (-2, 4), (-1, 1), (0, 0), (1, 1), (2, 4), (3, 9), ..
-
Rust연습)그래프 그리기 + 움직이는 별 표현하기(움직이는 gif만들기)코딩Coding/Rust연습 2022. 6. 15. 20:20
https://blog.naver.com/phy2sci/222262650395 3.RUST에서 Cargo.toml 설정하기 + 그래프 그리기(feat. Visual Studio Code ) 1. Cargo.toml 파일은 무엇인가 Cargo는 러스트의 빌드 시스템이자 패키지 관리 시스템이다. 그래프를 그... blog.naver.com 그래프 그리기 코드 ❤️ 움직이는 그림 만들기(별의 이동) https://blog.naver.com/phy2sci/222269440246 4.RUST에서 gif 움직그림 만들기(별의 이동) (feat. Visual Studio Code ) 1. 러스트 변수 선언은 왜 복잡해 보이는가 러스트에서 상수나 변수를 선언할 때에는 반드시 그럴 필요가 ... blog.naver.com
-
Rust연습] tuple연습❤️ & ndarray ❤️연습코딩Coding/Rust연습 2022. 6. 2. 00:42
Cargo.toml dependencies] ndarray = "0.15.4" main.rs // https://doc.rust-lang.org/rust-by-example/primitives/tuples.html // Tuples can be used as function arguments and as return values // https://rust-lang-nursery.github.io/rust-cookbook/science/mathematics/linear_algebra.html use ndarray::arr2; fn reverse(pair: (i32, bool)) -> (bool, i32) { // `let` can be used to bind the members of a tuple to..
-
Rust연습] Cow__120 Easy Rust in Korean: to_mut with Cow코딩Coding/Rust연습 2022. 4. 19. 23:05
1 use std::borrow::Cow; 2 3 #[derive(Debug)] 4 struct User<'a> { 5 name: Cow<'a, str>, 6 } 7 8 impl User<'_> { 9 fn is_borrowed(&self) {10 match &self.name {11 Cow::Borrowed(name) => println!("It's Borrowed: {name}"),12 Cow::Owned(name) => println!("It's owned: {name}"),13 }14 }15 }16 17 fn ..
-
Rust연습]Cow part2코딩Coding/Rust연습 2022. 4. 19. 23:01
1 use std::borrow::Cow; 2 3 #[derive(Debug)] 4 struct User<'a> { 5 name: Cow<'a, str>, 6 } 7 8 impl User<'_> { 9 fn is_borrowed(&self) {10 match &self.name {11 Cow::Borrowed(name) => println!("It's Borrowed: {name}"),12 Cow::Owned(name) => println!("It's owned: {name}"),13 }14 }15 }16 17 fn ..
-
Rust연습] cow_빨라서 최고borrow에서 적극 활용하자코딩Coding/Rust연습 2022. 4. 19. 22:19
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:?} ..
-
rust연습]vec벡터 끼리 합치기 + vec + vec append코딩Coding/Rust연습 2022. 4. 18. 01:46
fn main() { let mut vec = vec![1, 2, 3]; let mut my_vec2 = vec![236, 149, 136, 235, 133, 149, 32]; vec.append(&mut my_vec2); println!("{vec:?}"); } 결과 [1, 2, 3, 236, 149, 136, 235, 133, 149, 32] https://doc.rust-lang.org/std/vec/struct.Vec.html Vec in std::vec - Rust Consumes and leaks the Vec, returning a mutable reference to the contents, &'a mut [T]. Note that the type T must outlive the chos..