boxcap 0.1.0

Common project structure for creating rust projects
Documentation
//! The www module provdes web services including the following:
//! Scraper
//! FileHoster
//! Server

use super::Message;
use super::Service;
use std::error::Error;
use std::sync::mpsc::{Receiver, Sender};

/// Scraper is another type of service
#[derive(Default)]
pub struct Scraper {
    name: String,
    rx: Option<Receiver<Message>>,
    tx: Option<Sender<Message>>,
}

impl Scraper {
    /// creates a new instance of a service
    pub fn new() -> Self {
        Scraper {
            ..Default::default()
        }
    }
}

impl Service for Scraper {
    /// The messenger will keep track of everyones ID
    fn identify(&self) -> String {
        "scraper".to_string()
    }

    /// Run the particular service
    fn run(&self) -> Result<(), Box<dyn Error>> {
        Ok(())
    }
    /// sends a message to
    fn send(&self, msg: Message) -> Result<(), Box<dyn Error>> {
        Ok(())
    }

    /// sets the comm pair for the service
    fn set_comm_pair(&mut self, tx: Sender<Message>, rx: Receiver<Message>) -> () {
        self.tx = Some(tx);
        self.rx = Some(rx);
    }
}

/// The testing suite for the library can be seen here
#[cfg(test)]
mod tests {
    use super::*;

    use std::{fs, path::Path, thread::Scope};

    fn clean() -> Result<(), Box<dyn std::error::Error>> {
        // Define the path to the logs directory
        let log_dir_path = Path::new("logs/tests");

        // Check if the directory exists
        if log_dir_path.exists() {
            // Remove the directory and its contents
            fs::remove_dir_all(log_dir_path)?;
            println!("Successfully removed {}", log_dir_path.display());
        } else {
            println!("Directory {} does not exist.", log_dir_path.display());
        }

        Ok(())
    }

    #[test]
    fn test_scraper() {
        let s = Scraper::new();
    }
}