728x90
Getting Started
Install Rust for windows
1) Visual Studio 2022 설치
[include]
- Desktop Development with C++
- The Windows 10 or 11 SDK
- The English language pack component, along with any other language pack of your choosing
2) Rust 설치
3) 설치결과 확인
$ rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03)
# Check C:\Users\*****\.cargo\bin
$ ehco %path%
Create New Project
#create 'helloworld' project
$ cargo new helloworld --bin
$ cd helloworld
Hello World
fn main() {
println!("Hello world!");
}
Compiling and Running
# Compiling
$ rustc .\src\main.rs
# Running
$ main.exe
Hello world!
Cargo : Building and Running
# building
$ cargo build
Compiling helloworld v0.1.0 (c:/projects/helloworld)
Finished dev [unoptimized + debuginfo] target(s) in 2.85 secs
# run
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running `target/debug/helloworld`
Hello, world!
# check code errors
$ cargo check
# building for release (executable in target/release.)
cargo build --release
Cargo Commands
더보기
- We can create a project using cargo new.
- We can build a project using cargo build.
- We can build and run a project in one step using cargo run.
- We can build a project without producing a binary to check for errors using cargo check.
- Instead of saving the result of the build in the same directory as our code, Cargo stores it in the target/debug directory.
Variables and Mutabililty
- 기본 변수는 불변성(immutable : 재할당 불가) 가짐.
- 가변성(mutable : 재할당 가능)을 가진 변수는 let mut 로 선언.
- 상수는 const 키워드 사용. 상수 선언시에는 타입을 지정.
- 선언한 변수를 사용하지 않으면 컴파일러가 오류를 발생시킴.
fn main() {
let a = 5; // immutable (다른 값으로 재할당 안됨)
//a = 6; // riase error
println!("a={a}");
let mut b = 100; // mutable
println!("b={b}");
b = 101;
println!("b={b}");
const CONST_VAR:i32 = 200; // int32 type constant
println!("CONST_VAR={CONST_VAR}");
}
...ing...
Reference :
- The Rust Programming Language (rust-lang.org)
- The Cargo Book (rust-lang.org)
- What is rustc? - The rustc book (rust-lang.org)
- Rust Cheat Sheet & Quick Reference
- Rust Playground (rust-lang.org)
728x90
'Data Science' 카테고리의 다른 글
데이터 과학자에서 유용한 도구 5가지 (0) | 2024.02.23 |
---|---|
The Best Data Pipeline Solution List (0) | 2023.09.21 |
분석기법연재#0-대표적인 사용자 분석 기법들 (0) | 2022.11.11 |
분석기법연재#1-퍼널 분석(Funnel Analysis) (0) | 2022.11.11 |
[스크랩]How To Crack Spotify Data Science Technical Screen Interview (0) | 2022.04.02 |
최근댓글