본문 바로가기
Personal-Study/Rust

[Rust 문서 읽기] 1. Getting Started (시작하기)

by Aaron-Kim 2023. 1. 28.

The Rust Programming Language

- Installation (macOs)

  - rustup: command line tool for managing Rust versions, associated tools

    $ curl https://sh.rustup.rs -sSf | sh

    $ source $HOME/.cargo/env

    $ rustc --version
    $ rustup update
  - Rustacean

  - offline doc: rustup doc

- Hello, World!

  - IDE support via rust-analyzer
  - make a new source file and call it main.rs

  - filename convention: snake case

  - main function is special -> always first code that runs in every executable Rust program

  - indent 4 spaces (not a tab)

  - println!() is a Rust macro

  - end the line with a semicolon

  - compiling and running are separate steps

    $ rustc main.rs
  - Rust is an ahead-of-time compiled language

    - compile a program and give the executable to someone else,
       and they can run it even without having Rust installed

- Hello, Cargo!

  - Cargo: Rust's build system & package manager

    - building our code, downloading the libraries our code depends on, building those libraries, etc.

    - adding dependencies more easier

  $ cargo new <directory-name> --bin
     --bin options means make it to an executable application not for library

  - TOML (Tom's Obvious Minimal Language): Cargo's configuration format

  - package => crates

  - Using Cargo helps us organize our projects

  - cargo build and then run using ./target/debug/<file-name>

  - cargo build --release

  - cargo run (build + run)

  - cargo check (just for ensuring compiling + build)

  - Cargo figured out that the files hadn't changed, so it didn't rebuild but just ran the binary.
     If source code was modified, Cargo would have rebuilt for compiling before running it


Getting Started (영어)

시작하기 (한국어)

반응형

댓글