๊ด€๋ฆฌ ๋ฉ”๋‰ด

IT’s Portfolio

[Rust] Start Rust (Day 1) - Start Step ๋ณธ๋ฌธ

Development Study/Rust

[Rust] Start Rust (Day 1) - Start Step

f1r3_r41n 2022. 8. 7. 13:09
728x90
๋ฐ˜์‘ํ˜•

๐Ÿฆ€ Rust Day 1

Rust_book

๐Ÿณ๏ธ Rust

Rust๋Š” 2006๋…„ Mozilla ์—ฐ๊ตฌ์†Œ์˜ Graydon Hoare์˜ ์„ค๊ณ„๋กœ๋ถ€ํ„ฐ ์‹œ์ž‘๋˜์—ˆ๋‹ค.

Rust๋Š” Low ๋ ˆ๋ฒจ์˜ ์‹œ์Šคํ…œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ด๋ฉฐ, Static typing์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํŒŒ์ผ ํƒ€์ž„์— ๋‹ค์–‘ํ•œ ์˜ค๋ฅ˜๋ฅผ ๊ฐ์ง€ํ•จ.

์ฆ‰, OS ๊ฐœ๋ฐœ๊ณผ ์‹œ์Šคํ…œ์˜ ๊ฐœ๋…์„ ์ดํ•ดํ•˜๊ณ ์ž ํ•˜๋Š” ์‚ฌ๋žŒ์—๊ฒŒ๋Š” ๊ณต๋ถ€ํ•˜๊ธฐ ์ข‹์€ ์–ธ์–ด์ด๋‹ค.

ํ•˜์ง€๋งŒ ์ง„์ž… ์žฅ๋ฒฝ์ด ๋‚ฎ์ง€๋Š” ์•Š๋‹ค๊ณ  ํ•œ๋‹ค.

๐Ÿด Code

fn main(){
    println!("Hello, World!");
}
  • C์™€ ๊ฐ™์ด main ํ•จ์ˆ˜๋Š” ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  Rust ํ”„๋กœ๊ทธ๋žจ์—์„œ ๊ฐ€์žฅ ์ฒซ ๋ฒˆ์งธ๋กœ ์‹คํ–‰๋œ๋‹ค.
  • Rust์—์„œ์˜ ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” ํƒญ์ด ์•„๋‹Œ ๊ณต๋ฐฑ ๋ฌธ์ž 4๊ฐœ๋ฅผ ์ด์šฉํ•œ๋‹ค.
  • println(): ํ•จ์ˆ˜
  • println!(): ๋งคํฌ๋กœ

๐Ÿด‍โ˜ ๏ธ Static Language

  • ์ •์  ์–ธ์–ด์ธ Rust๋Š” ์ปดํŒŒ์ผ๊ณผ ์‹คํ–‰์„ ๋…๋ฆฝ์ ์ธ ๋‹จ๊ณ„๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.
    • Low Level Language
    • ํ”„๋กœ๊ทธ๋žจ์„ ์ปดํŒŒ์ผํ•ด์„œ ์ƒ์„ฑ๋œ ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ํƒ€์ธ์—๊ฒŒ ์ „๋‹ฌํ•˜๋ฉด ํ•ด๋‹น ์–ธ์–ด๋ฅผ ์„ค์น˜ํ•˜์ง€ ์•Š๊ณ ๋„ ์‹คํ–‰์ด ๊ฐ€๋Šฅ
  • Ruby, Python, Javascript๋Š” ๋™์  ์–ธ์–ด๋กœ ์ปดํŒŒ์ผ๊ณผ ์‹คํ–‰์„ ํ•˜๋‚˜์˜ ๋ช…๋ น์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค
    • High Level Language
    • ์–ธ์–ด๋‹น์‚ฌ์ž๊ฐ€ ํ•ด๋‹น ์–ธ์–ด๋ฅผ ์„ค์น˜ํ•ด์•ผ์ง€ ์‹คํ–‰์ด ๊ฐ€๋Šฅ

๐Ÿ Cargo

Rust์˜ ๋นŒ๋“œ ์‹œ์Šคํ…œ์ด์ž ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž

  • cargo new [project_name]: ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
    • ํ•ด๋‹น ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ๊นƒ ์ €์žฅ์†Œ๋กœ ์ดˆ๊ธฐํ™”
  • Cargo.toml: TOML(Tom's Obivous, Minimal Language) ํ˜•์‹, ํ•ด๋‹น ํ˜•์‹์€ ์นด๊ณ ์˜ ์„ค์ • ํŒŒ์ผ ํ˜•์‹
  • cargo build: ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ. target/debug/[project_name] ๊ฒฝ๋กœ์— ์‹คํ–‰ ํŒŒ์ผ์ด ์ €์žฅ๋จ
  • cargo run: ํ”„๋กœ์ ํŠธ ์ปดํŒŒ์ผ ๋ฐ ๊ฒฐ๊ณผ ํŒŒ์ผ ์‹คํ–‰
  • cargo check: ์ฝ”๋“œ์˜ ์ปดํŒŒ์ผ ์—ฌ๋ถ€๋ฅผ ์‹ ์†ํ•˜๊ฒŒ ๊ฒ€์‚ฌ. ์‹คํ–‰ ํŒŒ์ผ ์ƒ์„ฑํ•˜์ง€ ์•Š์Œ
  • cargo build --release: ์ตœ์ ํ™”๋œ ์ปดํŒŒ์ผ
    • cargo build์™€ ๋‹ค๋ฅด๊ฒŒ /target/release ๊ฒฝ๋กœ์— ์‹คํ–‰ ํŒŒ์ผ ์ƒ์„ฑ
    • cargo build๋Š” ๋” ๋นจ๋ฆฌ ์ž์ฃผ ์ปดํŒŒ์ผํ•˜๊ธฐ ์œ„ํ•จ
    • cargo build --release๋Š” ์ตœ์ข… ์™„์„ฑ๋œ ํ”„๋กœ๊ทธ๋žจ์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ์ตœ๋Œ€ํ•œ ๋น ๋ฅด๊ฒŒ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋„๋ก ์ปดํŒŒ์ผํ•˜๊ธฐ ์œ„ํ•จ
728x90
๋ฐ˜์‘ํ˜•
Comments