Home  Rust   Difference ...

difference between rust and cargo

cargo and rustc are both essential tools in the Rust ecosystem, but they serve different purposes and are used in different contexts. Here's a detailed comparison of the two:

rustc (Rust Compiler)

Example of Using rustc

  1. Create a file named main.rs with the following content:
    fn main() {
        println!("Hello, world!");
    }
    
  2. Compile the file:
    rustc main.rs
    
  3. Run the resulting executable:
    ./main   # On Unix-like systems
    main.exe # On Windows
    

cargo (Rust Package Manager and Build System)

Example of Using cargo

  1. Create a new project:
    cargo new hello_world
    cd hello_world
    
  2. Edit the src/main.rs file if needed, but it will have a default "Hello, world!" program:
    fn main() {
        println!("Hello, world!");
    }
    
  3. Build the project:
    cargo build
    
  4. Run the project:
    cargo run
    
  5. Test the project:
    cargo test
    

Comparison

Published on: Jun 19, 2024, 11:00 PM  
 

Comments

Add your comment