본문 바로가기

Rust61

[Rust] Variable : Python 코드 비교 예제 (58일차) [Python] if __name__ == '__main__': x = 1; print(x); # bind x again shadows old one from above x = 'i'; print(x) # declare, init something = None; x = 5; print("x, something", x, something); something = x * 5; print("x, something", x, something); # mutability y = 0; y = y * 2 + x; print(y); BLAH = 42; # only const by convention y *= BLAH; [Rust] fn main() { let x = 1; println!("x: {}", x); // bi.. 2023. 2. 18.
[Rust] Web Spider 예제 (57일차) # Cargo.toml # ... 중략 [dependencies] spider = "1.18.9" tokio = { version = "1.25.0", features = ["full"] } // src/main.rs extern crate spider; use spider::website::Website; use spider::tokio; #[tokio::main] async fn main() { let url = "https://choosealicense.com"; let mut website: Website = Website::new(&url); website.crawl().await; for page in website.get_pages() { println!("- {}", page.get_url.. 2023. 2. 12.
[Rust] 실시간 Chat App in Rocket (56일차) # root폴더/Cargo.toml [package] name = "chat-app" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] rocket = { version = "0.5.0-rc.1", features = ["json"] } [dev-dependecies] rand = "0.8" // root폴더/src/main.rs #[macro_use] extern crate rocket; #[cfg(test)] mod tests; use rocket::{tokio::sync::broadcast.. 2023. 2. 9.
[Rust] Web Crawler 예제 (55일차) ==> HTTP Request 생성 # Cargo.toml # ...중략 [dependencies] reqwest = { version = "0.11", features = ["json", "blocking"] }# Request with JSON parsing support futures = "0.3"# for our async / await blocks tokio = { version = "1.12.0", features = {"full"} } # for our async runtime // src/main.rs use std::io::Read; fn main() { let client = reqwest::blocking::Client::new(); let origin_url = "https://ro.. 2023. 2. 8.