pub async fn write_links(
    folder_path: PathBuf,
    mut rx: Receiver<links::Link>,
) -> Result<(), std::io::Error> {
    const CRAWLED_FILE_NAME: &str = r#"crawled.json"#;
    const NOT_CRAWLED_FILE_NAME: &str = r#"not_crawled.json"#;
    const MAIL_FILE_NAME: &str = r#"emails.json"#;
    const TEL_FILE_NAME: &str = r#"phone_nos.json"#;

    let mut crawled_writer = init_writer(CRAWLED_FILE_NAME, &folder_path).await?;
    let mut not_crawled_writer = init_writer(NOT_CRAWLED_FILE_NAME, &folder_path).await?;
    let mut mail_writer = init_writer(MAIL_FILE_NAME, &folder_path).await?;
    let mut tel_writer = init_writer(TEL_FILE_NAME, &folder_path).await?;

    while let Some(link) = rx.recv().await {
        let temp = format!("{}", link);
        match link.link_type {
            links::LinkType::Mail => write_json(&mut mail_writer, &temp).await?,
            links::LinkType::PhoneNo => write_json(&mut tel_writer, &temp).await?,
            links::LinkType::Other => {
                if link.crawled {
                    write_json(&mut crawled_writer, &temp).await?;
                } else {
                    write_json(&mut not_crawled_writer, &temp).await?;
                }
            }
        };
    }

    clean_writer(&mut crawled_writer).await?;
    clean_writer(&mut not_crawled_writer).await?;
    clean_writer(&mut mail_writer).await?;
    clean_writer(&mut tel_writer).await?;

    Ok(())
}
/// Function to write links to files.
/// Seperate files for crawled, not crawled, emails and phone no.
Function to write links to files.
Seperate files for crawled, not crawled, emails and phone no.
Function to write links to files . Seperate files for crawled not crawled emails and phone no .
pub async fn write_links(
    folder_path: PathBuf,
    mut rx: Receiver<links::Link>,
) -> Result<(), std::io::Error> {
    const CRAWLED_FILE_NAME: &str = r#"crawled.json"#;
    const NOT_CRAWLED_FILE_NAME: &str = r#"not_crawled.json"#;
    const MAIL_FILE_NAME: &str = r#"emails.json"#;
    const TEL_FILE_NAME: &str = r#"phone_nos.json"#;
    let mut crawled_writer = init_writer(CRAWLED_FILE_NAME, &folder_path).await?;
    let mut not_crawled_writer = init_writer(NOT_CRAWLED_FILE_NAME, &folder_path).await?;
    let mut mail_writer = init_writer(MAIL_FILE_NAME, &folder_path).await?;
    let mut tel_writer = init_writer(TEL_FILE_NAME, &folder_path).await?;
    while let Some(link) = rx.recv().await {
        let temp = format!("{}", link);
        match link.link_type {
            links::LinkType::Mail => write_json(&mut mail_writer, &temp).await?,
            links::LinkType::PhoneNo => write_json(&mut tel_writer, &temp).await?,
            links::LinkType::Other => {
                if link.crawled {
                    write_json(&mut crawled_writer, &temp).await?;
                } else {
                    write_json(&mut not_crawled_writer, &temp).await?;
                }
            }
        };
    }
    clean_writer(&mut crawled_writer).await?;
    clean_writer(&mut not_crawled_writer).await?;
    clean_writer(&mut mail_writer).await?;
    clean_writer(&mut tel_writer).await?;
    Ok(())
}
pub async fn write_links ( folder_path : PathBuf , mut rx : Receiver < links :: Link > , ) -> Result < ( ) , std :: io :: Error > { const CRAWLED_FILE_NAME : & str = r#"crawled.json"# ; const NOT_CRAWLED_FILE_NAME : & str = r#"not_crawled.json"# ; const MAIL_FILE_NAME : & str = r#"emails.json"# ; const TEL_FILE_NAME : & str = r#"phone_nos.json"# ; let mut crawled_writer = init_writer ( CRAWLED_FILE_NAME , & folder_path ) . await ? ; let mut not_crawled_writer = init_writer ( NOT_CRAWLED_FILE_NAME , & folder_path ) . await ? ; let mut mail_writer = init_writer ( MAIL_FILE_NAME , & folder_path ) . await ? ; let mut tel_writer = init_writer ( TEL_FILE_NAME , & folder_path ) . await ? ; while let Some ( link ) = rx . recv ( ) . await { let temp = format ! ( " " link ) ; match link . link_type { links :: LinkType :: Mail => write_json ( & mut mail_writer , & temp ) . await ? , links :: LinkType :: PhoneNo => write_json ( & mut tel_writer , & temp ) . await ? , links :: LinkType :: Other => { if link . crawled { write_json ( & mut crawled_writer , & temp ) . await ? ; } else { write_json ( & mut not_crawled_writer , & temp ) . await ? ; } } } ; } clean_writer ( & mut crawled_writer ) . await ? ; clean_writer ( & mut not_crawled_writer ) . await ? ; clean_writer ( & mut mail_writer ) . await ? ; clean_writer ( & mut tel_writer ) . await ? ; Ok ( ( ) ) }
Function to write links to files.
Function to write links to files .
folder_path
PathBuf
rx
Receiver<links::Link>
folder_path
PathBuf
rx
Receiver<links::Link>