diff --git a/src/main.rs b/src/main.rs index 9d5ea87..c34ef9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -519,44 +519,50 @@ fn handle_relative_connection( .rsplit_once('/') .map_or(relative_path, |(_, title)| title); - let handle_entry = |mut entry: &str, output: &mut TcpStream, level: usize| { - let level = level + 1; - let mut pki_path = path.to_path_buf(); - let mut audio_path = path.to_path_buf(); - if let Some((real_entry, _)) = entry.split_once(':') { - entry = real_entry - } - let pki_extension = if censored { "pkc" } else { "pki" }; - if relative_path.is_empty() { - pki_path.push(format!("{entry}.{pki_extension}")); - audio_path.push(format!("{entry}.mp3")); - } else { - pki_path.push(format!("{relative_path}/{entry}.{pki_extension}")); - audio_path.push(format!("{relative_path}/{entry}.mp3")); - } + fn entry_handler( + path: &Path, + relative_path: &str, + censored: bool, + ) -> impl Fn(&str, &mut TcpStream, usize) { + move |mut entry, output, level| { + let level = level + 1; + let mut pki_path = path.to_path_buf(); + let mut audio_path = path.to_path_buf(); + if let Some((real_entry, _)) = entry.split_once(':') { + entry = real_entry + } + let pki_extension = if censored { "pkc" } else { "pki" }; + if relative_path.is_empty() { + pki_path.push(format!("{entry}.{pki_extension}")); + audio_path.push(format!("{entry}.mp3")); + } else { + pki_path.push(format!("{relative_path}/{entry}.{pki_extension}")); + audio_path.push(format!("{relative_path}/{entry}.mp3")); + } - let Ok(file) = File::open(pki_path) else { - return; - }; + let Ok(file) = File::open(pki_path) else { + return; + }; - let _ = writeln!( - output, - "{entry}" - ); - - if Path::is_file(&audio_path) { let _ = writeln!( output, - "

" + "{entry}" + ); + + if Path::is_file(&audio_path) { + let _ = writeln!( + output, + "

" + ); + } + + convert_subheader( + BufReader::new(file).lines().map(Result::unwrap_or_default), + output, + level, ); } - - convert_subheader( - BufReader::new(file).lines().map(Result::unwrap_or_default), - output, - level, - ); - }; + } let Ok(pk_file) = File::open(file_paths.pk) else { unreachable!(); @@ -571,7 +577,7 @@ fn handle_relative_connection( lines.map(Result::unwrap_or_default), &mut stream, Settings::default() - .with_handler(handle_entry) + .with_handler(entry_handler(path, relative_path, censored)) .with_start_level(start_level) .with_use_textboxes(true), );