Skip to content

Commit c6d5b13

Browse files
feat: modules practice
1 parent 230fc2b commit c6d5b13

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

rustlang_book/iterators_closures/tshirt_giveaway/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ fn main() {
5555
let list = vec![1,2,3];
5656
println!("Before defining closure: {:?}", list);
5757

58+
59+
// The new thread may outlive the main thread, so we need to use move
60+
// to transfer ownership of the list to the new thread
5861
thread::spawn(move || println!("From thread: {:?}", list))
5962
.join()
6063
.unwrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "modules_exercise"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod hash {
2+
pub struct Hash<T> {
3+
pub hash: String,
4+
pub content: T,
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mod hasher{
2+
use crate::hash::hash::Hash;
3+
4+
pub fn hash<T>(data: T) -> Hash<T>{
5+
return Hash {
6+
hash: String::from("Placeholder"),
7+
content: data,
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod hasher;
2+
pub mod hash;
3+
pub mod storage;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub mod storage {
2+
use crate::hash::hash::Hash;
3+
4+
pub trait Storage {
5+
fn get() -> Hash<String>;
6+
fn put() -> bool;
7+
}
8+
}

0 commit comments

Comments
 (0)