摘要:
https://doc.rust-lang.org/book/ch05-01-defining-structs.html struct ColorClassicStruct { red: i32, green: i32, blue: i32 } struct ColorTupleStruct(i32 阅读全文
摘要:
fn main() { let cat = ("Furry McFurson", 3.5); let (name, age) = cat; println!("{} is {} years old.", name, age); } Example 2: #[test] fn indexing_tup 阅读全文
摘要:
fn main() { let a = 0..100; if a.len() >= 100 { println!("Wow, that's a big array!"); } else { println!("Meh, I eat arrays like that for breakfast."); 阅读全文
摘要:
struct Rectangle { width: i32, height: i32 } impl Rectangle { // Only change the test functions themselves pub fn new(width: i32, height: i32) -> Self 阅读全文
摘要:
pub fn is_even(num: i32) -> bool { num % 2 == 0 } /* This attribute indicates that the following module is a conditional compilation module that shoul 阅读全文
摘要:
Code has error: fn main() { let answer = square(3); println!("The square of 3 is {}", answer); } fn square(num: i32) -> i32 { num * num; } Error: ⚠️ C 阅读全文
摘要:
Constants variable always need to be annotated: const NUMBER: i32 = 3; fn main() { println!("Number {}", NUMBER); } 阅读全文
摘要:
Ref to : https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing fn main() { let number = "T-H-R-E-E"; // don't change this lin 阅读全文
摘要:
This lesson shows how to use a Rust loop to run a program infinitely. use std::io; use std::process; fn main() { loop { println!("Please enter a first 阅读全文
摘要:
In this lesson we'll learn how to exit a program using the std::process module in Rust and it's exit() method. use std::io; use std::process; fn main( 阅读全文
摘要:
In this lesson we'll explore how to unwrap a Result type using a language feature called Pattern Matching. use std::io; fn main() { let mut first = St 阅读全文
摘要:
This lesson discusses how to improve error handling by configuring custom error messages using the expect() function. use std::io; fn main() { let mut 阅读全文