코딩Coding/Rust연습
-
rust연습]u8_sting_stack저장하기bytes() / std::str코딩Coding/Rust연습 2022. 4. 18. 01:44
use std::str; fn main() { for b in "안녕 ".bytes() { println!("{}", b); } let a = vec![236, 149, 136, 235, 133, 149, 32]; let a = str::from_utf8(&a).unwrap(); println!("{a}"); } 결과 236 149 136 235 133 149 32 안녕 https://doc.rust-lang.org/std/str/fn.from_utf8.html from_utf8 in std::str - Rust Converts a slice of bytes to a string slice. A string slice (&str) is made of bytes (u8), and a byte slice (..
-
rust연습]10진수 숫자 16진수로 알아보는 방법& 16진수를 10진수 숫자로 알아보는 방법코딩Coding/Rust연습 2022. 4. 17. 23:36
10 진수 숫자 16진수로 알아보는 방법 fn main() { let i = 128150; println!("{i:x?}"); } 결과 1f496 16 진수 숫자 10 진수로 알아보는 방법 use std::i64; fn main() { let z = i64::from_str_radix("1F496", 16); println!("{:?}", z); } 결과 Ok(128150) 출처 : https://stackoverflow.com/questions/32381414/converting-a-hexadecimal-string-to-a-decimal-integer Converting a hexadecimal string to a decimal integer I'm writing a Rust program that..
-
rust연습] pi(𝜋)파이 1억자리까지 계산 하기코딩Coding/Rust연습 2022. 4. 16. 22:43
code 시작 1 use std::time::Instant; 2 3 const N: u64 = 100_000_000; 4 5 fn calculate_pi(n_terms: u64) -> f64 { 6 let numerator = 4.0; 7 let mut denominator = 1.0; 8 let mut operation = 1.0; 9 let mut pi = 0.0; 10 for _ in 0..n_terms { 11 pi += operation * (numerator / denominator); 12 denominator += 2.0; 13 operation *= -1.0; 14 } 15 pi 16 } 17 18 fn main() { 19 let start = Instant::now(); 20 let ..
-
Rust연습] 섀도 변수 y를 생성하는 match 표현식코딩Coding/Rust연습 2022. 4. 11. 17:25
fn main() { let x = Some(5); let y = 10; match x { Some(50) => println!("50"), Some(y) => println!("일치, y = {:?}", y), _ => println!("일치하지 않음, x = {:?}", x), } println!("결과: x = {:?}, y = {:?}", x, y); } 결과 일치, y = 5 결과: x = Some(5), y = 10 https://play.rust-lang.org/ Rust Playground play.rust-lang.org
-
rust 연습] iter(), zip() 연습코딩Coding/Rust연습 2022. 4. 11. 17:12
fn main() { let a1 = [1 ,2, 3]; let a2 = [4 ,5, 6]; let mut iter = a1.iter().zip(a2.iter()); println!("{:?}", iter.next()); println!("{:?}", iter.next()); } 결과 https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.zip Iterator in std::iter - Rust An iterator method that applies a function as long as it returns successfully, producing a single, final value. try_fold() takes two arg..
-
Rust연습] 16진수출력❤️HexRGB(Color) 연습출처 : Rust 101 - Lecture 1코딩Coding/Rust연습 2022. 4. 4. 20:30
https://www.youtube.com/watch?v=xOgdaL6A_AY&t=3351s 1시간 쯤 나옴. 1 enum Color { 2 RGB(u8, u8, u8), 3 Named(String), 4 HexRGB(u32), 5 } 6 7 fn main() { 8 let color = Color::HexRGB(12009742); 9 // let color = Color::Named("Rust".to_string()); 10 // let color = Color::RGB(183, 65, 14); 11 12 match color { 13 Color::RGB(r, g, b) => println!("R:{r}, G:{g}, B:{b}"), 14 Color::Named(s) => println!("{s}"),..
-
Rust연습]자연수 유니코드ℕ Unicode번호(16진수)알아보기코딩Coding/Rust연습 2022. 3. 23. 15:35
fn main() { let chars = 'ℕ'; let i = chars as u32; println!("{i:x?}"); } 결과 2115 https://play.rust-lang.org/ Rust Playground play.rust-lang.org rust연습]10진수 숫자 16진수로 알아보는 방법& 16진수를 10진수 숫자로 알아보는 방법 - https://economiceco.tistory.com/m/13283 rust연습]10진수 숫자 16진수로 알아보는 방법& 16진수를 10진수 숫자로 알아보는 방법 10 진수 숫자 16진수로 알아보는 방법 fn main() { let i = 128150; println!("{i:x?}"); } 결과 1f496 16 진수 숫자 10 진수로 알아보는 방법 ..