[Rust] ๊ฐœ๋…๋ถ€ํ„ฐ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ๊ตฌ์ถ•๊นŒ์ง€ ์ฐจ๊ทผ์ฐจ๊ทผ ์‹œ์ž‘ํ•ด๋ณด๊ธฐ

๋ฐ˜์‘ํ˜•

์š”์ฆ˜ ๋ชจ๋˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๊ฐ€ ๋งŽ์ด ๋‚˜์˜ค๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ตฌ๊ธ€์˜ Golang, ๋ชจ์งˆ๋ผ์˜ Rust ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ธ Clojure, Rescript ๋“ฑ ๋‹ค์–‘ํ•œ ์–ธ์–ด๊ฐ€ ๋งŽ์ด ๋‚˜์˜ค๊ณ  ์žˆ๋Š”๋ฐ์š”. ํŠนํžˆ ์ตœ๊ทผ์—๋Š” ๊ตฌ๊ธ€์—์„œ C++ ๋Œ€ํ•ญ ์–ธ์–ด๋กœ Carbon์ด๋ผ๋Š” ์–ธ์–ด๊นŒ์ง€๋„ ๋‚˜์™”์Šต๋‹ˆ๋‹ค.

 

์ด๋ฒˆ์— ๋‹ค๋ฃฐ ์ฃผ์ œ๋Š” ๋ฐ”๋กœ ๋ชจ์งˆ๋ผ์˜ Rust์ธ๋ฐ์š”. ์ตœ๊ทผ ๋ฆฌ๋ˆ…์Šค ์ปค๋„ ๊ฐœ๋ฐœ์—๋„ Rust ์–ธ์–ด๊ฐ€ ๊ณต์‹ ์ฑ„ํƒ๋˜์–ด ํ™”๋‘๊ฐ€ ๋˜๊ณ  ์žˆ๋Š” Rust์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

 

What is Rust?

์ œ๊ฐ€ ์ฒ˜์Œ Rust ์–ธ์–ด๋ฅผ ๋“ค์—ˆ์„ ๋•Œ๋Š” 3๋…„ ์ „, YouTube์˜ ์ผ€๋นˆ๋‹˜ ๋ฐฉ์†ก์—์„œ์˜€์Šต๋‹ˆ๋‹ค. ๊ทธ ๋•Œ๋ถ€ํ„ฐ ์ญˆ์šฑ ์•„๋ฌด๊ฒƒ๋„ ํ•ด์˜ค์ง€ ์•Š์•˜์—ˆ์Šต๋‹ˆ๋‹ค๋งŒ Golang๊ณผ Rust ๋‘˜ ์ค‘ ์—„์ฒญ ์ €์šธ์งˆ์„ ํ–ˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด์—ˆ์ฃ . ํ•˜์ง€๋งŒ ์ด์ œ๋Š” ์ž์‹ ์žˆ๊ฒŒ Rust ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•ด๋ด๋„ ๋  ๊ฒƒ ๊ฐ™์€ ์‹œ๊ธฐ๊ฐ€ ์˜ค๊ฒŒ ๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

https://www.rust-lang.org/

 

Rust Programming Language

A language empowering everyone to build reliable and efficient software.

www.rust-lang.org

๋จผ์ € Rust๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ์ค‘ ํ•˜๋‚˜๋กœ Mozilla์—์„œ 2010๋…„์— ๊ณต๊ฐœํ•œ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. type-safety, concurrencyํ•œ ์–ธ์–ด๋กœ ๋””์ž์ธ ๋˜์—ˆ์œผ๋ฉฐ ์‹œ์Šคํ…œ ๋ ˆ๋ฒจ๊ณผ ๋ฐ€์ ‘ํ•œ ๊ธฐ๋Šฅ์„ ๊ฐœ๋ฐœํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์—๊ฒŒ ์•„์ฃผ ์ ํ•ฉํ•œ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. 

 

๋” ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜์˜ ๋งํฌ์—์„œ ์ข€ ๋” ์•Œ์•„๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

https://rinthel.github.io/rust-lang-book-ko/ch00-00-introduction.html

 

์†Œ๊ฐœ - The Rust Programming Language

๋Ÿฌ์ŠคํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด, ๋Ÿฌ์ŠคํŠธ ์ž…๋ฌธ์„œ์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค. ๋Ÿฌ์ŠคํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋Š” ์—ฌ๋Ÿฌ๋ถ„์ด ๋” ๋น ๋ฅด๊ณ , ๋” ์•ˆ์ •์ ์ธ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์ž‘์„ฑํ•˜๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด ๋””์ž์ธ์—์„œ

rinthel.github.io

์ตœ๊ทผ์—๋Š” Linux, OpenCV, Turbopack(JS์˜ ๋ฒˆ๋“ค๋Ÿฌ) ๋“ฑ์—์„œ ๋‹ค์–‘ํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์œผ๋ฉฐ Node.js์˜ express์ธ ์›น ํ”„๋ ˆ์ž„์›Œํฌ๋„ ์ถœ์‹œ๋˜์–ด ๋”์šฑ ๊ทธ ๊ธฐ์„ธ๋ฅผ ๋„“ํ˜€๊ฐ€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

 

 

Install Rust

๊ทธ๋Ÿผ ์ด์ œ Rust๋ฅผ ์„ค์น˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ์šฐ๋ถ„ํˆฌ ๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ์—์„œ Rust๋ฅผ ์„ค์น˜ํ•ด๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

$ sudo apt install rustc cargo

APT ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋ฅผ ์ด์šฉํ•ด rustc์™€ cargo๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ cargo๋Š” Rust์˜ ๋นŒ๋“œ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

 

$ rustc --version

rustc --version ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด rust ๋ฒ„์ „์ด ์ž˜ ๋œจ๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•ด๋ด…์‹œ๋‹ค. ์ž˜ ๋œจ๊ณ  ์žˆ๋‹ค๋ฉด ์„ค์น˜๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

 

 

 

Run Visual Studio Code

VScode์—์„œ Rust๋ฅผ ์‹œ์ž‘ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. VScode์—์„œ Rust๋ฅผ ์‹œ์ž‘ํ•˜๋ ค๋ฉด rust-analyzer๋ผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

 

https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer 

 

rust-analyzer - Visual Studio Marketplace

Extension for Visual Studio Code - Rust language support for Visual Studio Code

marketplace.visualstudio.com

Visual Studio Code์˜ extensions๋ฅผ ์ด์šฉํ•ด์„œ๋„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Visual Studio Code๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ์™ผ์ชฝ ์‚ฌ์ด๋“œ๋ฐ”์—์„œ extensions๋ฅผ ํด๋ฆญํ•œ ๋‹ค์Œ rust-analyzer๋ฅผ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. 

 

 

 

 

Run IntelliJ IDEA or CLion

IntelliJ IDEA or CLion์—์„œ Rust๋ฅผ ์‹œ์ž‘ํ•˜๋ ค๋ฉด Rust ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

 

https://plugins.jetbrains.com/plugin/8182-rust

 

Rust - IntelliJ IDEs Plugin | Marketplace

The plugin provides support for Rust language.

plugins.jetbrains.com

ํ˜น์€ IDE์˜ Plugins ๋ฉ”๋‰ด์—์„œ๋„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Marketplace๋ฅผ ํด๋ฆญํ•ด Rust๋ฅผ ๊ฒ€์ƒ‰ํ•˜๋ฉด ๋งจ ์ƒ๋‹จ์— Rust ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

 

 

 

 

Init Project

์ด์ œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•ด ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Rust ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ๋Š” Rust ๋นŒ๋“œ ๋„๊ตฌ์ธ cargo๋ฅผ ์ด์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

$ cargo init [project name]

cargo init ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜๋ฉด ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

ํ•˜์ง€๋งŒ cargo.toml ํŒŒ์ผ์„ ๋ณด๋ฉด Plain Text ํฌ๋งท์˜ ํ˜•ํƒœ๋กœ ๋‚˜์˜ต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ VScode์—์„œ๋Š” ๋˜ ๋‹ค๋ฅธ ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

 

Better TOML ์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์„ค์น˜ํ•ด๋ด…๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฌ๋ฉด cargo.toml์ด ์ข€ ๋” ์ด์˜๊ฒŒ ๋‚˜์˜ต๋‹ˆ๋‹ค.

 

 

 

 

Build & Run

๊ฐ„๋‹จํžˆ ์šฐ๋ฆฌ๊ฐ€ init์œผ๋กœ ์ƒ์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ๋นŒ๋“œ, ์‹คํ–‰ํ•˜๋Š” ๋ฒ•์„ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

$ cargo build

ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ํ„ฐ๋ฏธ๋„์„ ์—ด๊ณ  cargo build๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํ”„๋กœ์ ํŠธ๊ฐ€ ์ปดํŒŒ์ผ ๋˜๊ณ  ์‹คํ–‰ ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฐ๋ฐ, ๋งŒ์•ฝ ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์ด CAMEL CASE๋กœ ๋˜์–ด ์žˆ๋‹ค๋ฉด Rust์—์„œ๋Š” warning์ด ๋‚˜ํƒ€๋‚˜๋ฉฐ SNAKE CASE๋กœ ํ•  ๊ฒƒ์œผ๋กœ ๊ถŒ๊ณ ํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ Snake case๋กœ ๋ณ€๊ฒฝํ•ด๋ด…๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฌ๋ฉด debug ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Œ? ๋ญ”๊ฐ€ ์–ด๋””์„œ ๋งŽ์ด ๋ณธ ๋“ฏํ•œ ๋นŒ๋“œ ๋ฐฉ๋ฒ•์ด์ฃ 

 

$ cargo build --release

cargo build์— release ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•˜๋ฉด ์ปดํŒŒ์ผ ์ตœ์ ํ™”๊ฐ€ ๋“ค์–ด๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ๋งŒ๋“ค์–ด์งˆ ๋•Œ ์ตœ์ ํ™” ๋œ ํ˜•ํƒœ์˜ ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ์ƒ์„ฑ๋˜์ง€๋งŒ ์ปดํŒŒ์ผ ์†๋„๋Š” ๋Š๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— ์ตœ์ข…์ ์œผ๋กœ ๋ฐฐํฌ๋  ๋ฐ”์ด๋„ˆ๋ฆฌ์— ๋Œ€ํ•ด์„œ๋งŒ ์ ์šฉํ•˜๋Š” ์˜ต์…˜์ž…๋‹ˆ๋‹ค.

 

์ด๊ฒƒ๋„ ์–ด๋”˜๊ฐ€์—์„œ ๋งŽ์ด ๋ณธ ๋ฐฉ์‹์ด์ฃ ? ๋ฐ”๋กœ Visual Studio์—์„œ ๋ณด์…จ์„ ๊ฒƒ ๊ฐ™์€๋ฐ์š”. Visual Studio์—์„œ C++ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์ปดํŒŒ์ผํ•˜๋ฉด debug ๋””๋ ‰ํ„ฐ๋ฆฌ์—, ๋งˆ์ง€๋ง‰์œผ๋กœ ์ตœ์ข… ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ฐฐํฌ์‹œ์—๋Š” release ์˜ต์…˜์„ ์‚ฌ์šฉํ•ด ์ปดํŒŒ์ผ ํ–ˆ์„ ๋•Œ์˜ ๋ชจ์Šต๊ณผ ๋™์ผํ•œ ํ˜•ํƒœ๋ฅผ ๋„๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

$ ./target/debug/{binary_name}

์ด์ œ target์— ์žˆ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์„ ์‹คํ–‰ํ•ด๋ด…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๊ธฐ๋ณธ ์ฝ”๋“œ์ธ Hello World๊ฐ€ ์ฐํžˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ง์ ‘ target ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ  cargo ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

$ cargo run

cargo run ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜๋ฉด ๋นŒ๋“œ์™€ ๋””๋ฒ„๊น…์„ ๋™์‹œ์— ์ง„ํ–‰ํ•ด์คŒ์œผ๋กœ์จ ๋นŒ๋“œ์‹œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋‚˜ํƒ€๋‚˜๊ณ , ์•ž์„œ ์ปดํŒŒ์ผ ๋œ ๊ฒฐ๊ณผ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ปดํŒŒ์ผ์„ ํ•˜์ง€ ์•Š๊ณ  ๋ฐ”๋กœ ์‹คํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

 

 

 

 

๋งˆ์น˜๋ฉฐ...

์•„์ฃผ ๊ฐ„๋‹จํ•œ ๋ชจ์Šต์œผ๋กœ Rust ์–ธ์–ด๋ฅผ ๋งŒ๋‚˜๋ดค์Šต๋‹ˆ๋‹ค. ์ž ๊น ์‚ฌ์šฉํ•ด๋ณด๋‹ˆ ์ปดํŒŒ์ผ๋Ÿฌ์˜ ๋ชจ์Šต๊ณผ ์‚ฌ์šฉ๋ฒ•์ด C++ ์ปดํŒŒ์ผ ๋ฐฉ์‹๊ณผ ๋งค์šฐ ํก์‚ฌํ•œ๋ฐ์š”. ๋‹ค๋งŒ ๋นŒ๋“œ ๋„๊ตฌ์— ๋Œ€ํ•œ ์‚ฌ์šฉ์€ Python Poetry์™€ ์œ ์‚ฌํ•œ ๋ชจ์Šต์ด์—ˆ์Šต๋‹ˆ๋‹ค.

 

๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ๋Š” Cargo ๋นŒ๋“œ ๋„๊ตฌ์— ๋Œ€ํ•ด์„œ ๋‹ค๋ค„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

๋ฐ˜์‘ํ˜•
TAGS.

Tistory Comments