From 62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2 Mon Sep 17 00:00:00 2001 From: hybrid Date: Sat, 31 Oct 2026 03:54:43 +0300 Subject: add: 7 craits smartpointers interior_mutability threads mutex hello-async async_concurrency multi_futures --- src/closures/Cargo.toml | 6 ++++++ src/closures/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/closures/Cargo.toml create mode 100644 src/closures/src/main.rs (limited to 'src/closures') diff --git a/src/closures/Cargo.toml b/src/closures/Cargo.toml new file mode 100644 index 0000000..a48c2e4 --- /dev/null +++ b/src/closures/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "closures" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/src/closures/src/main.rs b/src/closures/src/main.rs new file mode 100644 index 0000000..c16cf8b --- /dev/null +++ b/src/closures/src/main.rs @@ -0,0 +1,34 @@ +use std::thread; + +#[derive(Debug)] +struct Rectangle { + width: u32, + height: u32, +} + +fn main() { + let mut list_1 = vec![1, 2, 3]; + println!("[list_1] Before defining closure: {list_1:?}"); + + let mut borrows_mutably = || list_1.push(7); + + borrows_mutably(); + + println!("[list_1] After calling closure: {list_1:?}"); + + let list_2 = vec![1, 2, 3]; + println!("[list_2] Before defining closure: {list_2:?}"); + + thread::spawn(move || println!("[list_2] From thread: {list_2:?}")) + .join() + .unwrap(); + + let mut list_3 = [ + Rectangle { width: 10, height: 1 }, + Rectangle { width: 3, height: 5 }, + Rectangle { width: 7, height: 12 }, + ]; + + list_3.sort_by_key(|r| r.width); + println!("{list_3:#?}"); +} -- cgit v1.3.1