All current work

This commit is contained in:
2026-09-26 01:17:10 +03:00
commit 6f0139aae6
51 changed files with 9327 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "rust-training-fold-custumers"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "rust-training-fold-custumers"
version = "0.1.0"
edition = "2024"
[dependencies]
+35
View File
@@ -0,0 +1,35 @@
use std::{collections::HashMap};
struct Order {
customer: String,
price: u32,
paid: bool,
}
fn main() {
println!("Hello, world!");
let orders = vec![
Order { customer: "Alice".into(), price: 1200, paid: true },
Order { customer: "Bob".into(), price: 500, paid: false },
Order { customer: "Alice".into(), price: 800, paid: true },
Order { customer: "Charlie".into(), price: 2000, paid: true },
Order { customer: "Bob".into(), price: 1500, paid: true },
Order { customer: "Alice".into(), price: 300, paid: false },
];
let unique = orders.iter().fold(HashMap::new(), |mut acc, x| {
if x.paid {
*acc.entry(&x.customer).or_insert(0)+=x.price;
}
acc
});
let result = unique.iter().fold(String::new(), |mut acc, (x,y)| {
acc += &format!("{} {}\n", x, y);
acc
});
println!("{}",result);
}