mirror of
https://github.com/darkicewolf50/RustBrock.git
synced 2025-06-15 04:54:17 -06:00
finsihed The Rust Programming Language Bookgit add -Agit add -A
This commit is contained in:
parent
ff4c4fccee
commit
732235ab69
@ -1 +1 @@
|
|||||||
{"rustc_fingerprint":953660965870803700,"outputs":{"13331785392996375709":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/brock/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.85.1 (4eb161250 2025-03-15)\nbinary: rustc\ncommit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181\ncommit-date: 2025-03-15\nhost: x86_64-unknown-linux-gnu\nrelease: 1.85.1\nLLVM version: 19.1.7\n","stderr":""},"2063776225603076451":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/brock/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}}
|
{"rustc_fingerprint":517133967738620428,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.86.0 (05f9846f8 2025-03-31)\nbinary: rustc\ncommit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb\ncommit-date: 2025-03-31\nhost: x86_64-pc-windows-msvc\nrelease: 1.86.0\nLLVM version: 19.1.7\n","stderr":""},"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Brock\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
11
hello/404.html
Normal file
11
hello/404.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Hello!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Oops!</h1>
|
||||||
|
<p>Sorry, I don't know what you're asking for.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
7
hello/Cargo.lock
generated
Normal file
7
hello/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hello"
|
||||||
|
version = "0.1.0"
|
6
hello/Cargo.toml
Normal file
6
hello/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "hello"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
11
hello/hello.html
Normal file
11
hello/hello.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Hello!</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hello!</h1>
|
||||||
|
<p>Hi from Rust</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
82
hello/src/lib.rs
Normal file
82
hello/src/lib.rs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
use std::{ sync::{ mpsc, Mutex, Arc }, thread };
|
||||||
|
|
||||||
|
pub struct ThreadPool {
|
||||||
|
workers: Vec<Worker>,
|
||||||
|
sender: Option<mpsc::Sender<Job>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThreadPool {
|
||||||
|
/// Create a new ThreadPool.
|
||||||
|
///
|
||||||
|
/// The size is the number of threads in the pool.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// The `new` function will panic if the size is zero.
|
||||||
|
pub fn new(size: usize) -> ThreadPool {
|
||||||
|
assert!(size > 0);
|
||||||
|
|
||||||
|
let (sender, receiver) = mpsc::channel();
|
||||||
|
|
||||||
|
let receiver = Arc::new(Mutex::new(receiver));
|
||||||
|
|
||||||
|
let mut workers = Vec::with_capacity(size);
|
||||||
|
|
||||||
|
for id in 0..size {
|
||||||
|
workers.push(Worker::new(id, Arc::clone(&receiver)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadPool { workers, sender: Some(sender) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute<F>(&self, f: F) where F: FnOnce() + Send + 'static {
|
||||||
|
let job = Box::new(f);
|
||||||
|
|
||||||
|
self.sender.as_ref().unwrap().send(job).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ambitious side project
|
||||||
|
// pub fn build(size: usize) -> Result<ThreadPool, PoolCreationError> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for ThreadPool {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
drop(self.sender.take());
|
||||||
|
|
||||||
|
for worker in &mut self.workers.drain(..) {
|
||||||
|
println!("Shutting down worker {}", worker.id);
|
||||||
|
|
||||||
|
worker.thread.join().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Worker {
|
||||||
|
id: usize,
|
||||||
|
thread: thread::JoinHandle<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Worker {
|
||||||
|
fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
|
||||||
|
let thread = thread::spawn(move || {
|
||||||
|
loop {
|
||||||
|
let message = receiver.lock().unwrap().recv();
|
||||||
|
|
||||||
|
match message {
|
||||||
|
Ok(job) => {
|
||||||
|
println!("Worker {id} got a job; executing");
|
||||||
|
job();
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("Worker {id} disconnected; shutting down.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Worker { id, thread }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Job = Box<dyn FnOnce() + Send + 'static>;
|
74
hello/src/main.rs
Normal file
74
hello/src/main.rs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
use std::{
|
||||||
|
fs,
|
||||||
|
io::{ prelude::*, BufReader },
|
||||||
|
net::{ TcpListener, TcpStream },
|
||||||
|
thread,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
|
use hello::ThreadPool;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// this is not related I was just curious
|
||||||
|
// let test = fs::read_to_string("test.yaml").unwrap();
|
||||||
|
// println!("{}", test);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
|
||||||
|
|
||||||
|
let pool = ThreadPool::new(4);
|
||||||
|
|
||||||
|
for stream in listener.incoming().take(2) {
|
||||||
|
let stream = stream.unwrap();
|
||||||
|
pool.execute(|| {
|
||||||
|
handle_connection(stream);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Shutting down.");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_connection(mut stream: TcpStream) {
|
||||||
|
let buf_reader = BufReader::new(&stream);
|
||||||
|
|
||||||
|
// let http_request: Vec<_> = buf_reader
|
||||||
|
// .lines()
|
||||||
|
// .map(|result| result.unwrap())
|
||||||
|
// .take_while(|line| !line.is_empty())
|
||||||
|
// .collect();
|
||||||
|
let request_line = buf_reader.lines().next().unwrap().unwrap();
|
||||||
|
// no longer needed, here for debug and being useful
|
||||||
|
// println!("Request: {:#?}", http_request);
|
||||||
|
// if request_line == "GET / HTTP/1.1" {
|
||||||
|
// let status_line = "HTTP/1.1 200 OK";
|
||||||
|
// let contents = fs::read_to_string("./hello.html").unwrap();
|
||||||
|
// let length = contents.len();
|
||||||
|
|
||||||
|
// let res = format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");
|
||||||
|
|
||||||
|
// stream.write_all(res.as_bytes()).unwrap();
|
||||||
|
// } else {
|
||||||
|
// let status_line = "HTTP/1.1 404 NOT FOUND";
|
||||||
|
// let contents = fs::read_to_string("404.html").unwrap();
|
||||||
|
// let length = contents.len();
|
||||||
|
|
||||||
|
// let res = format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");
|
||||||
|
|
||||||
|
// stream.write_all(res.as_bytes()).unwrap();
|
||||||
|
// }
|
||||||
|
|
||||||
|
let (status_line, filename) = match &request_line[..] {
|
||||||
|
"GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"),
|
||||||
|
"GET /sleep HTTP/1.1" => {
|
||||||
|
thread::sleep(Duration::from_secs(5));
|
||||||
|
("HTTP/1.1 200 OK", "hello.html")
|
||||||
|
}
|
||||||
|
_ => ("HTTP/1.1 404 NOT FOUND", "404.html"),
|
||||||
|
};
|
||||||
|
|
||||||
|
let contents = fs::read_to_string(filename).unwrap();
|
||||||
|
let length = contents.len();
|
||||||
|
|
||||||
|
let res = format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}");
|
||||||
|
|
||||||
|
stream.write_all(res.as_bytes()).unwrap();
|
||||||
|
}
|
41
hello/test.yaml
Normal file
41
hello/test.yaml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
Diamond Tier:
|
||||||
|
- Schulich School of Engineering:
|
||||||
|
LogoUrl: https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQj9L3ZGK6WtOmJbzxmCzRxwLXYKGC5SDcAKHb0ScfbUmbtG0IujQt6eQDaI_Pm9g4DZvc&usqp=CAU
|
||||||
|
Url: https://schulich.ucalgary.ca/
|
||||||
|
DescriptionAboutSponsor: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eu magna in diam consectetur rhoncus vel nec turpis. Sed finibus mi eu sem varius faucibus. Donec semper erat et bibendum pharetra. Suspendisse cursus lorem sed nisi semper, a rutrum nunc luctus. Nunc ullamcorper enim id orci interdum ultrices. Donec vestibulum nunc vel nisl pretium tempus. Morbi quis ante et ligula eleifend eleifend. Proin bibendum maximus elit vitae congue. Vivamus egestas, ex in tempor posuere, ligula nunc iaculis massa, in imperdiet dui justo eu dolor. Nullam placerat velit quis sem mattis, laoreet pharetra elit tempor.
|
||||||
|
Platinum Tier:
|
||||||
|
- Platinum Sponsor Name:
|
||||||
|
LogoUrl:
|
||||||
|
Url:
|
||||||
|
DescriptionAboutSponsor:
|
||||||
|
Gold Tier:
|
||||||
|
- Suri:
|
||||||
|
LogoUrl: https://lh5.googleusercontent.com/WJsBsmcLypQhY0MMOLQtJSGFXrLQqPKNc3502rYUGKPCq_SfS9CxuoB3n541Kn9bKPm2b5aixCnYsCVYZAts2Y8xvmOHWL3nnbKtWUkE1KoFYYQ4bXUlikfF0NPIynxhzQ=w1280
|
||||||
|
Url: https://www.surimanufacturing.com/
|
||||||
|
DescriptionAboutSponsor:
|
||||||
|
- SKF:
|
||||||
|
LogoUrl: https://www.skf.com/v2/assets/img/skf-logo-white.svg
|
||||||
|
Url: https://www.skf.com/ca/en
|
||||||
|
DescriptionAboutSponsor: I am not sure
|
||||||
|
- WRMA:
|
||||||
|
LogoUrl: https://wildrosemx.com/wp-content/uploads/2021/08/wild-rose-motocross-calgary-rasterized.png
|
||||||
|
Url: https://wildrosemx.com/
|
||||||
|
DescriptionAboutSponsor:
|
||||||
|
Silver Tier:
|
||||||
|
- Encore Metals:
|
||||||
|
LogoUrl: https://www.encoremetals.com/assets/images/logos/encore-metals-logo.png
|
||||||
|
Url: https://www.encoremetals.com/
|
||||||
|
DescriptionAboutSponsor: Metal supplier
|
||||||
|
- CNOOC:
|
||||||
|
LogoUrl: https://cnoocinternational.com/img/cnooc-logo.png
|
||||||
|
Url: https://cnoocinternational.com/
|
||||||
|
DescriptionAboutSponsor:
|
||||||
|
Bronze Tier:
|
||||||
|
- Redbull:
|
||||||
|
LogoUrl: "https://img.redbull.com/redbullcom/static/redbullcom-logo_double-with-text.svg"
|
||||||
|
Url: https://www.redbull.com/ca-en/
|
||||||
|
DescriptionAboutSponsor:
|
||||||
|
- Canada Action:
|
||||||
|
LogoUrl:
|
||||||
|
Url:
|
||||||
|
DescriptionAboutSponsor:
|
@ -1 +1 @@
|
|||||||
{"rustc_fingerprint":953660965870803700,"outputs":{"13331785392996375709":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/brock/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"2063776225603076451":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/brock/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.85.1 (4eb161250 2025-03-15)\nbinary: rustc\ncommit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181\ncommit-date: 2025-03-15\nhost: x86_64-unknown-linux-gnu\nrelease: 1.85.1\nLLVM version: 19.1.7\n","stderr":""}},"successes":{}}
|
{"rustc_fingerprint":517133967738620428,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.86.0 (05f9846f8 2025-03-31)\nbinary: rustc\ncommit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb\ncommit-date: 2025-03-31\nhost: x86_64-pc-windows-msvc\nrelease: 1.86.0\nLLVM version: 19.1.7\n","stderr":""},"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\Brock\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""}},"successes":{}}
|
Loading…
x
Reference in New Issue
Block a user