This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"privateKey": "[PRIVATE_KEY]", | |
"publicKey": "[PUBLIC_KEY]", | |
"encryptionKey": "[ENCRYPTION_KEY]" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Gabriel Hayes | |
// Rust Worker-Runloop Implementation | |
use std::cell::RefCell; | |
use std::rc::Rc; | |
use std::time::Duration; | |
use std::thread; | |
struct Worker { | |
job: Rc<RefCell<FnMut(i64)>>, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Practice with Cell Smart Pointers | |
// Cells grant interior mutability: | |
// Cells allow you to mutate the interior value, these can only be used with | |
// values on the stack or Copy values | |
// RefCells allow you mutate the interior reference use this for values on the heap | |
// or Clone values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple Axis-Aligned Bounding Box | |
// Author: Gabriel Hayes | |
#[derive(Debug)] | |
struct AABB { | |
x: i64, | |
y: i64, | |
wx: i64, | |
hy: i64, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::time::Duration; | |
fn main() { | |
concurrency_demo_1(); | |
concurrency_demo_2(); | |
} | |
// this simply demonstrates how to move data from an outer scope into a thread's scope: | |
fn concurrency_demo_1() { | |
let v = vec![1, 2, 3]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::sync::mpsc; | |
use std::time::Duration; | |
fn main() { | |
// start by creating a channel | |
let (tx, rx) = mpsc::channel(); | |
// we need to create a clone of the transmitter because each thread actually | |
// owns the copy we give it... and it's greedy so it won't give it back :( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We need a reference counting pointer to have multiple references to a single object | |
use std::rc::Rc; | |
// We need a RefCell to be able to internally mutate an immutable value | |
use std::cell::RefCell; | |
#[derive(Debug)] | |
// definition of a linked list | |
enum List { | |
// We may have multiple references to a given list object, therefore we need Rc<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// we will use weak references with the Rc<T> (reference counting pointer) type | |
// weak references allow us to make references to a value that will -not- keep it alive | |
// this is perfect in the intsance of children, as we will soon see | |
use std::rc::{Rc,Weak}; | |
use std::cell::RefCell; | |
// this example builds upon the last by storing a vector of children as well as a parent | |
#[derive(Debug)] | |
struct Node { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::thread; | |
use std::time::Duration; | |
// this simple example spwans a thread and runs an operation while running the same operation on the main thread | |
fn main() { | |
// the thread::spawn function expects a Closure; Rust closure syntax is |params_list...| { expr body } | |
// if the exprsesion is one line curly braces can be omitted | |
// type annotations are optional in closures, as Rust implicitly infers the types the first time the Closure is called | |
let handle = thread::spawn(|| { | |
for i in 1..10 { |
NewerOlder