This file contains hidden or 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
// [dependencies] | |
// async-std = { version = "1.12.0", features = ["attributes"] } | |
// futures = "0.3.30" | |
use async_std::{ | |
future::timeout, | |
sync::{Arc, Mutex}, | |
}; | |
use futures::{ | |
channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}, | |
futures::stream::StreamExt, |
This file contains hidden or 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
// petgraph v0.6.5 | |
use petgraph::graph::{NodeIndex, DiGraph}; | |
fn number_children(graph: &DiGraph<(), ()>, parent: NodeIndex, depth: usize) -> Vec<(NodeIndex, usize, usize)> { | |
let mut tree = Vec::new(); | |
let mut index = 0; | |
// Start numbering the children from index 0 | |
for child in graph.neighbors(parent) { | |
tree.push((child, index, depth)); |
This file contains hidden or 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
// petgraph v0.6.5 | |
use petgraph::graph::DiGraph; | |
use petgraph::visit::{EdgeRef, Topo}; | |
fn main() { | |
// Create a new directed graph | |
let mut graph = DiGraph::new(); | |
// Add nodes and edges (similar to previous examples) | |
let a1 = graph.add_node("A1"); |
This file contains hidden or 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
#[derive(Debug, Clone, Serialize, Deserialize)] | |
pub struct CustomGraph { | |
pub graph: petgraph::Graph<MakelineNode, ()>, | |
} | |
impl PartialEq for CustomGraph { | |
fn eq(&self, other: &Self) -> bool { | |
graph_eq(&self.graph, &other.graph) | |
} |
This file contains hidden or 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::any::TypeId; | |
// Define some example types | |
struct Foo; | |
struct Bar; | |
struct Baz; | |
// Define a function to perform type-based pattern matching and return the value | |
fn match_type<T: 'static>(value: T) -> Option<T> { | |
// Get the TypeId of the value |
This file contains hidden or 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 self::error::GenerationError; | |
use std::{ | |
collections::HashMap, | |
ops::{Deref, DerefMut}, | |
}; | |
pub type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>; | |
pub mod error { | |
use super::*; |
This file contains hidden or 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
//#![no_std] | |
use serde::{Deserialize, Serialize}; | |
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)] | |
pub enum State { | |
State1, | |
State2, | |
State3, | |
} |
This file contains hidden or 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::{ | |
collections::{HashMap, VecDeque}, | |
sync::{Arc, RwLock, Weak}, | |
}; | |
use uuid::Uuid; | |
#[derive(Default)] | |
pub struct Broker<T: Clone> { | |
subscribers: Arc<RwLock<HashMap<String, Vec<Weak<RwLock<Client<T>>>>>>>, | |
} |
This file contains hidden or 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
// [dependencies] | |
// bincode = "1.3.3" | |
// serde = { version = "1.0.197", features = ["derive"] } | |
// snap = "1.1.1" | |
use bincode::{deserialize, serialize}; | |
use serde::{de::DeserializeOwned, Serialize}; | |
use snap::{read::FrameDecoder, write::FrameEncoder}; | |
use std::{ | |
fs::{File, OpenOptions}, |
This file contains hidden or 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
[package] | |
name = "snapper" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
fake = "2.5" | |
snap = "1.0" |