-
Rust❤️ increment(++) decrement(--)하는 법코딩Coding/★Rust★기초★Syntax 2022. 6. 10. 17:48728x90
https://www.reddit.com/r/rust/comments/jf66eu/why_are_there_no_increment_and_decrement/
Why are there no increment (++) and decrement (--) operators in Rust?
I've just started learning Rust, and it struck me as a bit odd that `x++` and `x--` aren't a part of the Rust language. I did some research, and I...
www.reddit.com
increment(++)for i in 0..1000 { println!("{:?}", i); }
decrement(--)하는 법for i in (0..1000).rev() { println!("{:?}", i); }
예시use rayon::prelude::*; use std::time::{Duration, Instant}; fn increment_all(input: &mut [i32]) { input.par_iter_mut().for_each(|p| *p += 1); for i in (0..1000).rev() { println!("{:?}", i); } } fn main() { let now_1 = Instant::now(); let now_2 = Instant::now(); print!("thread1 : "); print!("{:?}", increment_all(&mut [10])); let elapsed1= now_1.elapsed().as_millis(); print!("thread2 : "); print!("{:?}", increment_all(&mut [10])); let elapsed2 = now_2.elapsed().as_millis(); println!("1nd thread elapse : {elapsed1} millsec"); println!("2nd thread elapse : {elapsed2} millsec"); }
결과2 1 0 ()1nd thread elapse : 10 millsec 2nd thread elapse : 10 millsec
https://stackoverflow.com/questions/25170091/how-to-make-a-reverse-ordered-for-loopHow to make a reverse ordered for loop?
Editor's note: This question was asked before Rust 1.0 was released and the .. "range" operator was introduced. The question's code no longer represents the current style, but some answers below uses
stackoverflow.com
반응형'코딩Coding > ★Rust★기초★Syntax' 카테고리의 다른 글
Rust❤️] i32::MIN과 fold methods활용법 (0) 2022.06.16 Rust❤️take & collect methods 사용법 1분 53초에 나옴 & skip(3분30초 (0) 2022.06.16 Lock-Free to Wait-Free Simulation in Rust (part 1& 2) | Jon Gjengset (0) 2022.06.13 Rust❤️ Time (sleep, chrono) (0) 2022.06.11 Rust❤️Part3수준 높고 배울게 많음-Use Vec and HashMap to compute Median and Mode (0) 2022.06.10 Rust❤️) #cfg(target_os = "linux")운영체제 별로 실행하는 코드 control하기 ❤️ (0) 2022.06.10 Rust❤️) parse() | ParseInError | More Result챕터에 나옴 (0) 2022.06.09 Rust❤️)is_ok() & is_err() | enum Result<T, E> {Ok(T), Err(E),} (0) 2022.06.09