Rust is proving to be a productive tool for collaborating among large teams of developers with varying levels of systems programming knowledge. | Divyansh Rai

Shared on Rust

editor-img
Divyansh Rai
Jul 6, 2022
shared in

Rust is proving to be a productive tool for collaborating among large teams of developers with varying levels of systems programming knowledge. Cargo is the included dependency manager and build tool, that makes adding, compiling, and managing dependencies painless and consistent across the Rust ecosystem.

# A simple function of rust - Hello World! fn main() { println!("Hello, world!"); } On Linux or macOS, Save the file and go back to your terminal window. enter the following commands to compile and run the file: $ rustc main.rs $ ./main Hello, world! On Windows, enter the command .\main.exe instead of ./main: > rustc main.rs > .\main.exe Hello, world!

Using Cargo: Cargo comes installed with Rust if you used the official installers Creating a new Project with cargo: $ cargo new hello_cargo $ cd hello_cargo Now open src/main.rs and take a look at this file: fn main() { println!("Hello, world!"); }

$ cargo build This command creates an executable file in target/debug/hello_cargo (or target\debug\hello_cargo.exe on Windows) rather than in your current directory. You can run the executable with this command: $ ./target/debug/hello_cargo Hello, world!

$ cargo run We can also use cargo run to compile the code and then run the resulting executable all in one command

$ cargo check Cargo also provides a command called cargo check. This command quickly checks your code to make sure it compiles but doesn’t produce an executable: Checking hello_cargo v0.1.0 (file:///projects/hello_cargo) Finished dev [unoptimized + debuginfo] target(s)


Tagged users
editor-img
Rajat
@28-mace-windu
I don't know. I'm pretty much done with everythinghh!
Checkout related posts on: