oh just cargo fmt it all

This commit is contained in:
2026-10-06 20:58:16 +01:00
parent 37a6496906
commit d154b1e376
17 changed files with 119 additions and 116 deletions
+18 -20
View File
@@ -1,14 +1,14 @@
#![allow(dead_code)]
#![allow(unused_variables)]
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
pub fn run() {
println!("\n=== defining and instantiating structs ===\n");
@@ -21,8 +21,6 @@ pub fn run() {
// structure.
// Here is an example of a user data structure.
let user1 = User {
active: true,
username: String::from("username123hello"),
@@ -35,25 +33,26 @@ pub fn run() {
let uemail = String::from("newemail@example.com");
println!("struct mut email: {uemail}");
let user2 = build_user(String::from("bartal.baek@example.com"), String::from("baraldur12345"));
let user2 = build_user(
String::from("bartal.baek@example.com"),
String::from("baraldur12345"),
);
let u2name = user2.username;
let u2email = user2.email;
println!("the name of user2 is {u2name}, and the email is {u2email}");
let update_user1 = User {
email: String::from("bxtal@example.com"),
..user1
};
email: String::from("bxtal@example.com"),
..user1
};
// TUPLE STRUCTS
// groupings of related values, where the tuple is named, but the values are unnamed.
let black = Color(0,0,0);
let origin = Point(0,0,0);
let black = Color(0, 0, 0);
let origin = Point(0, 0, 0);
let Point(x,y,z) = origin;
let Point(x, y, z) = origin;
println!("the y point is {y} and the x point is {x}, and the z point is {z}");
@@ -65,7 +64,6 @@ pub fn run() {
// OWNERSHIP OF STRUCT DATA
// Usage of lifetimes, in chap 10, no more explaination here.
}
fn build_user(email: String, username: String) -> User {
+1 -1
View File
@@ -1,6 +1,6 @@
mod defining_structs;
mod struct_program;
mod methods;
mod struct_program;
fn main() {
defining_structs::run();
+1 -4
View File
@@ -38,10 +38,7 @@ pub fn run() {
};
let sq = Rectangle::square(5);
println!(
"The area of the rectangle is {} square feet",
rect1.area()
);
println!("The area of the rectangle is {} square feet", rect1.area());
println!("The rectangle has a nonzero width, it is {}", rect1.width());
println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2));
+4 -7
View File
@@ -13,11 +13,11 @@ pub fn run() {
println!(
"The are of the rectangle is {} square pixels",
area(width1,height1)
area(width1, height1)
);
// program with struct tuple
let rect1 = (30,50);
let rect1 = (30, 50);
println!(
"The tuple struct rectancle is {} square pixels",
tuple_struct_area(rect1)
@@ -32,21 +32,18 @@ pub fn run() {
println!(
"The struct rectangle is {} square pixels",
struct_area(&rect2)
);
);
dbg!(&rect2);
println!("this is also debug for rect2\n{rect2:#?}");
println!("this is also debug but not as pretty with :? for rect2\n{rect2:?}");
}
fn area(width: u32, height: u32) -> u32 {
width * height
}
fn tuple_struct_area(dimensions: (u32,u32)) -> u32 {
fn tuple_struct_area(dimensions: (u32, u32)) -> u32 {
dimensions.0 * dimensions.1
}