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
'Personal-Study > Rust' 카테고리의 다른 글
[Rust 문서 읽기] 4. Understanding Ownership (소유권 이해하기) (0) | 2023.01.29 |
---|---|
[Rust 문서 읽기] 3. Common Programming Concepts (보편적인 프로그래밍 개념) (0) | 2023.01.29 |
[Rust 문서 읽기] 2. Programming a Guessing Game (추리 게임 튜토리얼) (0) | 2023.01.29 |
[Rust 문서 읽기] Introduction (소개) (0) | 2023.01.28 |
[Rust 문서 읽기] Foreword (들어가기에 앞서) (0) | 2023.01.28 |
댓글