0
0
Rustprogramming~15 mins

Match overview in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Match Overview
๐Ÿ“– Scenario: You are building a simple program to describe the weather using Rust's match expression. This helps you choose a message based on the weather condition.
๐ŸŽฏ Goal: Create a Rust program that uses a match expression to print a message about the weather condition.
๐Ÿ“‹ What You'll Learn
Create a variable called weather with the value "sunny"
Create a variable called message that uses a match expression on weather
Use match arms for "sunny", "rainy", and a default arm
Print the message variable
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Using <code>match</code> expressions helps programs make decisions based on different inputs, like choosing messages or actions depending on conditions.
๐Ÿ’ผ Career
Understanding <code>match</code> is important for Rust programming jobs, especially when handling different cases clearly and safely.
Progress0 / 4 steps
1
Create the weather variable
Create a variable called weather and set it to the string "sunny".
Rust
Need a hint?

Use let to create a variable and assign the string "sunny".

2
Create the message variable with match
Create a variable called message that uses a match expression on weather. Use arms for "sunny" and "rainy" that return appropriate messages, and a default arm that returns "Unknown weather".
Rust
Need a hint?

Use match weather { ... } and include arms for "sunny", "rainy", and a default arm _.

3
Add a print statement to show the message
Add a println! statement to print the message variable.
Rust
Need a hint?

Use println!("{}", message); to display the message.

4
Run the program and see the output
Run the program to see the printed message about the weather.
Rust
Need a hint?

Check the console output after running the program.