반응형
Rust 학습의 첫걸음은 개발 환경 설정입니다.
이 글에서는 rustup, cargo, rust-analyzer, clippy 설정까지 한 번에 정리해보겠습니다.
📦 1. Rust 설치
Rust는 rustup 도구로 설치합니다.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
설치 완료 후 다음 명령어로 확인:
rustc --version
cargo --version
🖥️ 2. 개발 환경: Cursor IDE + rust-analyzer
Cursor IDE는 VSCode 기반으로, AI 기능과 Rust 개발에 모두 적합합니다.
확장 설치
- rust-analyzer 플러그인 설치
- 기능: 자동완성, 타입 추론, 오류 표시, 네비게이션 등
🔧 3. 첫 프로젝트 생성
프로젝트 디렉토리는 생성하지 않는다.
프로젝트 디렉토리가 위치해야 하는 곳에서 cargo new [프로젝트 이름] 을 실행하면, 디렉토리를 포함한 프로젝트 셋팅이 된다.
cd ~/workspace/rust-learning
cargo new hello-rust
% cargo new hello-rust
Creating binary (application) `hello-rust` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
생성되는 디렉토리 구조
hello-rust/
├── .git/ # 기본 Git 초기화 (Cargo 기본 설정)
├── .gitignore
├── Cargo.toml # Rust 프로젝트 메타 정보 (Java의 pom.xml과 유사)
└── src/
└── main.rs # 엔트리포인트(main 함수 포함)
main.rs
fn main() {
println!("Hello, Rust + Cursor!");
}
% cargo run
Compiling hello-rust v0.1.0 (/Users/tweak/workspace/rust-learning/hello-rust)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.43s
Running `target/debug/hello-rust`
Hello, Rust + Cursor!
디렉토리는 자동으로 생성되며 .git, Cargo.toml, src/main.rs 포함
✅ 4. clippy 설정 (코드 검사기)
Clippy는 Rust용 정적 분석 도구입니다.
Clippy는 꼭 써야 할까?
네. Rust는 워낙 “안전”과 “명확함”을 중요시하기 때문에,
Clippy는 거의 모든 프로젝트에서 기본으로 사용됩니다.
- 컴파일은 되지만 Rust스럽지 않은 코드를 찾아냅니다
- 퍼포먼스 잠재적 이슈, 불필요한 clone, panic 가능성 등을 사전에 탐지합니다
- 팀 내 코드 스타일 통일에도 도움
VSCode 설정 (Cursor에서 settings.json에 추가)
"rust-analyzer.check": {
"command": "clippy"
}
잘못된 형식 예시 (주의): "checkOnSave": { "command": "clippy" } ← ❌ 오류 발생
🧪 5. 실습 과제
- cargo new hello-rust 로 프로젝트 생성
- main.rs 수정
fn main() {
println!("Hello, Rust + Cursor!");
}
- cargo run 실행
- clippy 경고를 유도하고 수정해보기
✍️ 정리
도구 | 역할 |
rustc | 컴파일러 |
cargo | 빌드 및 패키지 관리 도구 |
rust-analyzer | LSP 기반 개발 지원기 |
clippy | 코드 스타일 & 성능 점검 도구 |
Cargo.toml | Rust의 pom.xml |
다음 강의에서는 변수, 함수, 타입, 제어문 등 기초 문법을 Java와 비교하며 실습합니다.
Rust의 철학인 불변성, 표현력 있는 match, 스코프 기반 메모리를 직접 경험해보세요!
반응형