본문 바로가기

전체 글293

[Rust] Ownership(소유권) 기초 예제 : Struct (33일차) [예제 코드_1] #[derive(Debug)] struct Movie { title: String, } fn main() { let movie = Movie { title: String::from("Rust") }; do_something(movie); } fn do_something(movie: Movie) { println!("Movie: {:?}!", movie); } [실행 결과] Movie: Movie { title: "Rust" }! [예제 코드_2] #[derive(Debug)] struct Movie { title: String, } fn main() { let movie = Movie { title: String::from("Rust") }; do_something(movie); pri.. 2023. 1. 15.
[Rust] Ownership(소유권) 기초 예제 : i32 (32일차) [예제 코드_1] fn main() { let age: i32 = 25; do_something(age); } fn do_something(age: i32) { println!("Hello, {}", age); } [실행 결과] Hello, 25! [예제 코드_2] fn main() { let age: i32 = 25; do_something(age); println!("{}", age); } fn do_something(age: i32) { println!("Hello, {}", age); } [실행 결과] Hello, 25! 25 [예제 코드_3] fn main() { let age: i32 = 25; do_something(&age); println!("{}", age); } fn do_someth.. 2023. 1. 14.
[Rust] Ownership(소유권) 기초 예제 : String (31일차) [예제 코드_1] fn main() { let name = String::from("Rust"); do_something(name); } fn do_something(name: String) { println!("Hello, {}", name) } [출력 결과] Hello, Rust! [예제 코드_2] fn main() { let name = String::from("Rust"); do_something(name); println!("{}", name); } fn do_something(name: String) { println!("Hello, {}", name); } [출력 결과] error[E0382]: borrow of moved value: `name` --> src/main.rs:4:20 [예제.. 2023. 1. 13.
[Rust] Iterator 예제 (30일차) fn main() { let v1 = vec![1, 2, 3]; let v1_iter = v1.iter(); for val in v1_iter { println!("got: {}", val); } } #![allow(unused)] fn main() { #[test] fn iterator_demonstration() { let v1 = vec![1, 2, 3]; let mut v1_iter = v1.iter(); assert_eq!(v1_iter.next(), Some(&1)); assert_eq!(v1_iter.next(), Some(&2)); assert_eq!(v1_iter.next(), Some(&3)); assert_eq!(v1_iter.next(), None); } } #[test] fn it.. 2023. 1. 12.
[Rust] Command Line Program 제작 : 환경변수 활용 (29일차) // 지난 lib.rs 코드를 이어서 수정. 아래 명령어를 입력해보자 // $cargo run to poem.txt // $CASE_INSENSITIVE=1 cargo run to poem.txt use std::error::Error; use std::fs::File; use std::io::prelude::*; use std::env; pub struct Config { pub query: String, pub filename: String, pub case_sensitive: bool, } impl Config { pub fn new(args: &[String]) -> Result(query: &str, contents: &'a str) -> Vec(query: &str, contents: &'a .. 2023. 1. 11.
[MySQL] DISTINCT 조회 Data 중복 없이 조회 SELECT DISTINCT [Column 이름] FROM [Table 이름]; SELECT DISTINCT 'index' FROM 'people' https://blog.naver.com/PostView.naver?blogId=tang1013&logNo=222291646107&parentCategoryNo=&categoryNo=51&viewDate=&isShowPopularPosts=true&from=search 2023. 1. 11.
[Rust] Command Line Program 제작 (28일차) // Cargo.toml 과 동일한 위치의 최상단 경로에 poem.txt 생성 I'm nobody! Who are you? Are you nobody, too? Then there's a pair of us — don't tell! They'd banish us, you know. How dreary to be somebody! How public, like a frog To tell your name the livelong day To an admiring bog! // $cargo run the poem.txt 명령어를 입력하여 실행 use std::env; use std::fs::File; use std::io::prelude::*; fn main() { let args: Vec = env::arg.. 2023. 1. 10.
[Rust] Testing 예제_2 (27일차) fn prints_and_returns_10(a: i32) -> i32 { println!("I got the vaue {}", a); 10 } #[cfg(test)] mod tests { use super::*; #[test] fn this_test_will_pass() { let value = prints_and_returns_10(4); assert_eq!(10, value); } #[test] fn this_test_will_fail() { let value = prints_and_returns_10(8); assert_eq!(5, value); } } pub fn add_two(a: i32) -> i32 { a + 2 } #[cfg(test)] mod tests { use super::*; #[.. 2023. 1. 9.