1장. 시작하기

Gillilab - TechLog·2024년 11월 17일

Rust

목록 보기
2/21

1장. 시작하기

1. Rust 설치하기

  • rustup을 통해 Rust의 최신 안정 버전을 설치할 수 있습니다
    # Windows, macOS, Linux 설치 명령어
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • 설치 후 버전 확인
    rustc --version
    cargo --version
  • rustup을 통한 버전 업데이트
    rustup update

2. Hello, World! 작성하기

  • 첫 번째 Rust 프로그램 작성
    // main.rs
    fn main() {
        println!("Hello, World!");
    }
  • rustc로 컴파일하고 실행하기
    rustc main.rs
    ./main # Linux/macOS
    .\main.exe # Windows

3. Cargo 사용하기

  • 새 프로젝트 생성

    cargo new hello_cargo
    cd hello_cargo
  • Cargo.toml 구성 예시

    [package]
    name = "hello_cargo"
    version = "0.1.0"
    edition = "2021"
    
    [dependencies]
  • 프로젝트 빌드 및 실행

    cargo build     # 빌드
    cargo run       # 빌드 및 실행
    cargo check     # 컴파일 체크만 수행
  • 릴리즈 빌드

    cargo build --release  # 최적화된 릴리즈 버전 빌드

4. IDE 설정

  • rust-analyzer를 통한 IDE 지원
  • VS Code, IntelliJ 등 주요 IDE에서 Rust 플러그인 설치 가능
  • 코드 자동완성, 에러 체크, 디버깅 지원

5. 문서 참고하기

  • 로컬 문서 보기: rustup doc
  • 표준 라이브러리 문서
  • 온라인 Rust Book 참조

참조: https://doc.rust-lang.org/book/ch01-00-getting-started.html

0개의 댓글