chore: formatting
This commit is contained in:
@@ -2,8 +2,8 @@ use std::env;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Mutex, Once,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
@@ -168,10 +168,11 @@ pub fn log(level: LogLevel, message: &str) {
|
||||
}
|
||||
// But ALSO write to file if configured (file logging bypasses buffering)
|
||||
if let Ok(mut log_file) = LOG_FILE.lock()
|
||||
&& let Some(file) = log_file.as_mut() {
|
||||
let _ = writeln!(file, "{}", formatted_message_plain);
|
||||
let _ = file.flush();
|
||||
}
|
||||
&& let Some(file) = log_file.as_mut()
|
||||
{
|
||||
let _ = writeln!(file, "{}", formatted_message_plain);
|
||||
let _ = file.flush();
|
||||
}
|
||||
} else {
|
||||
// Write to file if configured, otherwise to stderr
|
||||
if let Ok(mut log_file) = LOG_FILE.lock() {
|
||||
|
||||
@@ -369,7 +369,7 @@ fn bit_padding(input: &str) -> Vec<u8> {
|
||||
//check if bit length % 512 is 448 (64 less than 512)
|
||||
while (input_vector.len() * 8) % 512 != 448 {
|
||||
input_vector.push(0_u8); // push in another 8-bit 0 padded value until the correct
|
||||
// result is reached;
|
||||
// result is reached;
|
||||
}
|
||||
|
||||
let length_bits_as_u8_array = split_u64_to_u8_array(bit_length);
|
||||
@@ -467,8 +467,7 @@ fn all_alphanumeric_correct_hash() {
|
||||
|
||||
#[test]
|
||||
fn repeated_numbers_correct_hash() {
|
||||
let repeated_number_str =
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
||||
let repeated_number_str = "12345678901234567890123456789012345678901234567890123456789012345678901234567890";
|
||||
|
||||
assert_eq!("57edf4a22be3c955ac49da2e2107b67a", md5(repeated_number_str));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, mpsc};
|
||||
use std::thread;
|
||||
|
||||
type Job = Box<dyn FnOnce() + Send + 'static>;
|
||||
@@ -89,37 +89,39 @@ impl Worker {
|
||||
_active_threads: Arc<AtomicUsize>,
|
||||
_total_threads: usize,
|
||||
) -> Worker {
|
||||
let thread = thread::spawn(move || loop {
|
||||
let message = receiver.lock().unwrap().recv();
|
||||
match message {
|
||||
Ok(Message::NewJob(job)) => {
|
||||
// let active =
|
||||
// active_threads.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
// trace!(
|
||||
// "Thread {} started job (active: {}/{})",
|
||||
// id,
|
||||
// active,
|
||||
// total_threads
|
||||
// );
|
||||
let thread = thread::spawn(move || {
|
||||
loop {
|
||||
let message = receiver.lock().unwrap().recv();
|
||||
match message {
|
||||
Ok(Message::NewJob(job)) => {
|
||||
// let active =
|
||||
// active_threads.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
// trace!(
|
||||
// "Thread {} started job (active: {}/{})",
|
||||
// id,
|
||||
// active,
|
||||
// total_threads
|
||||
// );
|
||||
|
||||
job();
|
||||
job();
|
||||
|
||||
// let active =
|
||||
// active_threads.fetch_sub(1, Ordering::SeqCst) - 1;
|
||||
// trace!(
|
||||
// "Thread {} finished job (active: {}/{})",
|
||||
// id,
|
||||
// active,
|
||||
// total_threads
|
||||
// );
|
||||
}
|
||||
Ok(Message::Terminate) => {
|
||||
// Received termination signal
|
||||
break;
|
||||
}
|
||||
Err(_) => {
|
||||
// Channel disconnected
|
||||
break;
|
||||
// let active =
|
||||
// active_threads.fetch_sub(1, Ordering::SeqCst) - 1;
|
||||
// trace!(
|
||||
// "Thread {} finished job (active: {}/{})",
|
||||
// id,
|
||||
// active,
|
||||
// total_threads
|
||||
// );
|
||||
}
|
||||
Ok(Message::Terminate) => {
|
||||
// Received termination signal
|
||||
break;
|
||||
}
|
||||
Err(_) => {
|
||||
// Channel disconnected
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user