Hone logo
Hone
Problems

Build Your First Rust Binary Crate

This challenge will guide you through the fundamental process of creating a Rust binary crate. Understanding how to structure and build a simple executable program is the first step towards developing more complex applications and tools in Rust.

Problem Description

Your task is to create a new Rust binary crate named hello_rust. This crate should contain a single executable file that, when run, prints the message "Hello, Rust!" to the console. You will need to use Cargo, Rust's build system and package manager, to create, build, and run your project.

Key Requirements:

  • Create a new Rust binary project using Cargo.
  • The project should be named hello_rust.
  • The executable, when run, must output the exact string "Hello, Rust!" followed by a newline.
  • The project should be buildable and runnable using standard Cargo commands.

Expected Behavior:

When you navigate to the project directory and run cargo run, the program should execute and display:

Hello, Rust!

Examples

Example 1:

  • Action: Create a new binary project and run it.
  • Command:
    cargo new hello_rust --bin
    cd hello_rust
    cargo run
    
  • Output:
    Hello, Rust!
    
  • Explanation: The cargo new command creates the basic project structure. The default main.rs file generated by cargo new --bin usually contains a println!("Hello, world!"); statement. You will modify this to print "Hello, Rust!". cargo run then compiles and executes the program.

Example 2:

  • Action: After modifying src/main.rs to print the correct message, build the project in release mode and then run the executable directly.
  • Command:
    cargo build --release
    ./target/release/hello_rust
    
  • Output:
    Hello, Rust!
    
  • Explanation: cargo build --release compiles the code with optimizations. The executable is then located in ./target/release/. Running this executable directly produces the desired output.

Constraints

  • The project must be created using Cargo.
  • The crate name must be hello_rust.
  • The output message must be exactly "Hello, Rust!" (case-sensitive, with a newline).

Notes

  • Cargo is your primary tool for this challenge. Familiarize yourself with cargo new, cargo run, and cargo build.
  • The primary logic will reside in the src/main.rs file.
  • Pay close attention to the exact wording and capitalization of the output message.
  • This challenge is designed to introduce you to the basic workflow of Rust development with Cargo.
Loading editor...
rust