INSTALL

  • install - 설치 후 ~/.bashrc~/.cargo 자동 환경 설정
$ curl https://sh.rustup.rs -sSf | sh -- --help
  • rustup 업데이트/ 제거
$ rustup update
$ rustup self uninstall
  • rustc 컴파일러 버전확인
$ rustc --version

Hello World

$ vim hello_world.rs
fn main() {
 #println! 함수가 아닌 매크로
 println!("Hello, world!");
}
$ rustc hello_world.rs

Cargo를 통한 개발

$ cargo new hello_cargo --bin
$ cd hello_cargo
$ vim src/main.rs
fn main() {
 println!("Hello, world!");
}
  • ./target/debug/hello_cargo 로 바이너리 생성
$ cargo run   # compile and run
$ cargo run   # run only: source is not changed
$ cargo check # compile only no exe file create (rapid compile and test)
$ cargo clean # cleanup all object and binary files

$ cargo run -- --help #실행파일 인자를 받아서 실행할 때

$ cargo build 
$ cargo build --release (optimize for release)
  • 모듈을 사용할 경우
$ cargo add ansi_term #자동으로 Cargo.toml에 모듈이름과 버전이 등록된다.
$ vim src/main.rs #use ansi_term::xxxx 을 넣고 코딩
$ cargo run

Build From Git

$ git clone someurl.com/someproject
$ cd someproject
$ cargo build

reference