본문 바로가기

Rust61

[Rust] String 예제 (17일차) fn main() { let mut a = String::new(); a = a + "Rust on running"; println!("{}", a); let data = "initial contents"; let s = data.to_string(); println!("{}", s); // the method also works on a literal directlys: let s = "finale contents".to_string(); println!("{}", s); } fn main() { let mut s = String::from("foo"); s.push_str("bar"); println!("{}", s); let mut s1 = String::from("foo"); let s2 = "b.. 2022. 12. 28.
[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.