Code reformatting.

This commit is contained in:
Revertron
2021-06-09 20:36:36 +02:00
parent 2d12fd0447
commit d513c29cfe
40 changed files with 546 additions and 815 deletions
+6 -3
View File
@@ -1,14 +1,17 @@
use crate::event::Event;
use crate::simplebus::Bus;
use std::sync::Mutex;
use lazy_static::lazy_static;
use uuid::Uuid;
use crate::event::Event;
use crate::simplebus::Bus;
lazy_static! {
static ref STATIC_BUS: Mutex<Bus<Event>> = Mutex::new(Bus::new());
}
pub fn register<F>(closure: F) -> Uuid where F: FnMut(&Uuid, Event) -> bool + Send + Sync + 'static {
pub fn register<F>(closure: F) -> Uuid
where F: FnMut(&Uuid, Event) -> bool + Send + Sync + 'static {
STATIC_BUS.lock().unwrap().register(Box::new(closure))
}
+4 -5
View File
@@ -1,17 +1,16 @@
use std::net::IpAddr;
use std::num;
pub use constants::*;
use rand::Rng;
#[cfg(not(target_os = "macos"))]
use thread_priority::*;
pub use constants::*;
use crate::dns::protocol::DnsRecord;
pub mod constants;
pub mod simplebus;
pub mod eventbus;
pub mod simplebus;
/// Convert bytes array to HEX format
pub fn to_hex(buf: &[u8]) -> String {
@@ -120,14 +119,14 @@ pub fn is_yggdrasil(addr: &IpAddr) -> bool {
pub fn is_yggdrasil_record(record: &DnsRecord) -> bool {
match record {
DnsRecord::UNKNOWN { .. } => {}
DnsRecord::A { .. } => { return false }
DnsRecord::A { .. } => return false,
DnsRecord::NS { .. } => {}
DnsRecord::CNAME { .. } => {}
DnsRecord::SOA { .. } => {}
DnsRecord::PTR { .. } => {}
DnsRecord::MX { .. } => {}
DnsRecord::TXT { .. } => {}
DnsRecord::AAAA { addr, .. } => { return is_yggdrasil(&IpAddr::from(*addr))}
DnsRecord::AAAA { addr, .. } => return is_yggdrasil(&IpAddr::from(*addr)),
DnsRecord::SRV { .. } => {}
DnsRecord::OPT { .. } => {}
}
+3 -2
View File
@@ -1,6 +1,7 @@
use uuid::Uuid;
use std::collections::HashMap;
use uuid::Uuid;
pub struct Bus<T> {
listeners: HashMap<Uuid, Box<dyn FnMut(&Uuid, T) -> bool + Send + Sync>>
}
@@ -33,8 +34,8 @@ mod tests {
use std::thread;
use std::time::Duration;
use crate::Bus;
use crate::event::Event;
use crate::Bus;
#[test]
fn test1() {