Rust 소개
메모리 관리
- Rust에는 GC가 없다
- GC는 구동될 때 실행 중인 모든 스레드를 잠시 정지시켜 반응성을 좋지 않게 한다
- 대신 소유권과 수명 개념을 통해 컴파일타임에 메모리를 관리한다
Exception
- Rust에는 Exception가 없다
- 러스트는 오류를 두가지로 나눈다
비동기 프로그래밍
- Rust는 언어 차원에서 async/await 등 비동기 프로그래밍을 지원한다
패키지 관리 도구
- Rust는 Cargo라는 패키지 관리자를 제공한다
- 모듈은 Crate라는 단위로 묶여서 Crates.io를 통해 executable 혹은 library 형태로 배포할 수 있다
Rust 개발 환경 설치
curl https://sh.rustup.rs -sSf | sh -s
- 설치하니 ~/.bashrc에 rust 환경설정 명령어가 입력되어있다
sijin@Sijin:~$ tail -n 1 ~/.bashrc
. "$HOME/.cargo/env"
- 실행시켜준뒤 cargo version을 확인해보자
sijin@Sijin:~$ source ~/.bashrc
sijin@Sijin:~$ cargo --version
cargo 1.89.0 (c24e10642 2025-06-23)
Rust hello-world
sijin@Sijin:~$ cargo new hello-world
Creating binary (application) `hello-world` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
sijin@Sijin:~$ tree hello-world/
hello-world/
├── Cargo.toml
└── src
└── main.rs
2 directories, 2 files
- src/main.rs는 아래와 같이 만들어졌다
fn main() {
println!("Hello, world!");
}
sijin@Sijin:~/hello-world$ cargo run
Compiling hello-world v0.1.0 (/home/sijin/hello-world)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.49s
Running `target/debug/hello-world`
Hello, world!
- 러스트 컴파일러인 rustc를 직접 사용해 빌드 및 실행할 수 있지만 권장되지 않는다
- 모듈 단위 빌드로 통합 관리하는 방법이 더 권장된다
sijin@Sijin:~/hello-world$ rustc src/main.rs
sijin@Sijin:~/hello-world$ ls
Cargo.lock Cargo.toml main src target
sijin@Sijin:~/hello-world$ ./main
Hello, world!
vscode
- 편의를 위해 rust-analyzer extension을 설치하자