Rust
Rust
Learning RUST programming language and documenting my learning
Hello World - Rust !
hello_world.rs
fn main(){
println!("Hello world")
}To compile rust code
$ rustc hello_world.rsRun the binary
$ ./hello_worldCargo
cargo is rust’s build tool and package manager, to manage dependencies and its versions,basically crates. cargo uses TOML format stands for Tom’s Obvious Minimal language,which is cargo’s configuration format.
Cargo useful commands
$ cargo new hello_cargo --vcs=git
$ cd hello_cargoon creating a new cargo project the source files are to be present within the src/ directory and also Config.toml file is generated.
- cargo build
$cargo build
Compiling hello_cargo v0.1.0 (/home/vinay/learn/rust/hello_cargo)
Finished dev [unoptimized + debuginfo] target(s) in 0.17sa target/ directory is created
the binary is within the target/debug directory
$ ls target/debug/
build deps examples hello_cargo hello_cargo.d incremental$ ./target/debug/hello_cargo
Hello, world!- cargo run
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/hello_cargo`
Hello, world!instead of two commands of compiling and running the binary, cargo run is a simple command,which compiles and runs the binary
- cargo check
compiles the code but does not produce an executable.A
$ cargo check
Checking hello_cargo v0.1.0 (/home/vinay/learn/rust/hello_cargo)
Finished dev [unoptimized + debuginfo] target(s) in 0.02s