본문 바로가기

Study56

[Rust] Vector 예제 (16일차) // main.rs fn main() { // Create an empty vector let mut v: Vec = Vec::new(); // Push some elements onto the vector v.push(1); v.push(2); v.push(3); // Access elements of the vector using indexing let third: &i32 = &v[2]; println!("The third element is {}", third); // Iterate over the elements of the vector for i in &v { println!("{}", i); } } use std::vec::Vec; fn main() { // Create a new, empt.. 2022. 12. 27.
[Rust] Use - Rust Programming 15일차 - Use 를 통해 Scope 내 함수를 간단히 호출 pub mod a { pub mod series { pub mod of { pub fn nested_modules() {} } } } use a::series::of::nested_modules; fn main() { nested_modules(); } - 열거형의 Variant 가져오기 enum TrafficLight { Red, Yellow, Green, } use TrafficLight::{Red, Yellow}; fn main() { let red = Red; let yellow = Yellow; let green = TrafficLight::Green; } - * (Glob)을 통해 모두 가져오기 enum TrafficLight { Red, .. 2022. 12. 22.
[Rust] Pub&Private - Rust Programming 14일차 - module private & pulbic - 모든 Code Default 값은 Private - Privacy Rules ==> 만일 어떤 Item이 Public이면, 부모 Module의 어디서든 접근 가능 ==> Item이 Private면 같은 File 내 부모 Module 및 해당 부모의 자식 Module만 접근 가능. ==> lib.rs 파일 내 Code 를 Pub mod를 통해 나누기 mod outermost { pub fn middle_function() {} fn middle_secret_function() {} mod inside { pub fn inner_function() {} fn secret_function() {} } } fn try_me() { outermost::middle.. 2022. 12. 21.
[Rust] Rust Programming 13일차 - if let 예제를 공부 [예제 code_1] // 비교를 위한 Match Code // Make `optional` of type `Option` let optional = Some(7); match optional { Some(i) => { println!("This is a really long string and `{:?}`", i); // ^ Needed 2 indentations just so we could destructure // `i` from the option. }, _ => {}, // ^ Required because `match` is exhaustive. Doesn't it seem // like wasted space? }; [예제 code_2] fn main() { /.. 2022. 12. 20.