Skip to content

gndzkrkc/hello-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

hello-rust

A beginner-friendly Rust project to learn the basics of Rust programming language and Cargo package manager.

📋 Table of Contents

About

This project is a starting point for learning Rust basics. It includes a simple "Hello, world!" program to verify your Rust and Cargo installation, and serves as a foundation for exploring Rust concepts like variables, functions, ownership, pattern matching, and more.

Prerequisites

Before you begin, make sure you have the following installed:

  • Rust - The Rust programming language
  • Cargo - Rust's package manager and build system (comes with Rust)

Installation

Install Rust and Cargo

The easiest way to install Rust and Cargo is using rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After installation, restart your terminal and verify the installation:

rustc --version
cargo --version

Quick Start

Run the Project

To build and run the default "Hello, world!" program:

cargo run

You should see:

Hello, world!

Build the Project

To compile the project without running it:

cargo build

This creates a debug executable in target/debug/.

Release Build

To create an optimized release build:

cargo build --release

This creates a release executable in target/release/ with optimizations enabled.

Project Structure

hello-rust/
├── Cargo.toml           # Project manifest (package info, dependencies)
├── src/
│   └── main.rs          # Main entry point of the program
└── target/              # Build artifacts (auto-generated)
    ├── debug/           # Debug builds
    └── release/         # Release builds

Cargo.toml

This file contains your project's configuration:

  • [package] - Metadata about your project (name, version, edition)
  • [dependencies] - External packages your project depends on
  • [dev-dependencies] - Dependencies only used for development

src/main.rs

The entry point of your Rust program. The main() function is where your program starts executing.

Available Commands

Command Description
cargo run Compile and run the project
cargo build Compile the project in debug mode
cargo build --release Compile the project with optimizations
cargo check Check if the project compiles without building
cargo test Run tests
cargo fmt Format code according to Rust style guidelines
cargo clippy Lint your code for common mistakes and improvements
cargo clean Remove the target directory
cargo doc --open Generate and open local documentation

Learning Resources

Official Documentation

Interactive Learning

  • Rustlings - Small exercises to get you used to reading and writing Rust code
  • Exercism - Rust Track - Curated programming exercises with mentor feedback

Community

Next Steps

Here are some ideas to expand your learning:

  1. Add More Functions - Create and call additional functions in main.rs

    fn greet(name: &str) {
        println!("Hello, {}!", name);
    }
  2. Work with Variables - Learn about immutability and ownership

    let x = 5;
    let mut y = 10;
    y += x;
  3. Create Modules - Organize code into separate modules

    • Create a new file in src/ and use mod declarations
  4. Add Dependencies - Explore external crates from crates.io

    • Edit Cargo.toml to add a dependency
    • Example: serde = "1.0" for serialization
  5. Write Tests - Learn Rust's testing framework

    #[cfg(test)]
    mod tests {
        #[test]
        fn it_works() {
            assert_eq!(2 + 2, 4);
        }
    }
  6. Build a Larger Project - Structure your code into libraries and binaries

Useful Tips

  • Use cargo check frequently during development - it's faster than a full build
  • Read compiler errors carefully - Rust's error messages are extremely helpful
  • Use rustfmt to automatically format your code: cargo fmt
  • Use clippy to catch common mistakes: cargo clippy
  • Check the official docs - The standard library documentation is comprehensive and searchable

License

This project is open source and available under the MIT License.


Happy learning! 🦀 Welcome to the Rust community!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages