diff --git a/crates/voicevox_core/src/voice_model.rs b/crates/voicevox_core/src/voice_model.rs index 6064d847d..c2d848ed5 100644 --- a/crates/voicevox_core/src/voice_model.rs +++ b/crates/voicevox_core/src/voice_model.rs @@ -448,13 +448,56 @@ pub(crate) mod tokio { } } + type InferenceModelEntries<'manifest> = + (Option>,); + + struct InferenceModelEntry { + indices: EnumMap, + manifest: M, + } + + #[ext] + impl async_zip::base::read::seek::ZipFileReader> { + async fn from_file(path: &Path) -> anyhow::Result + where + Self: Sized, // 自明 + { + let zip = async_fs::File::open(path).await.with_context(|| { + // fs-errのと同じにする + format!("failed to open file `{}`", path.display()) + })?; + let zip = futures_util::io::BufReader::new(zip); + let zip = async_zip::base::read::seek::ZipFileReader::new(zip).await?; + Ok(zip) + } + + fn find_index(&self, filename: &str) -> anyhow::Result { + let (idx, _) = self + .file() + .entries() + .iter() + .enumerate() + .find(|(_, e)| e.filename().as_str().ok() == Some(filename)) + .with_context(|| "could not find `{filename}`")?; + Ok(idx) + } + + async fn read_file(&mut self, index: usize) -> anyhow::Result> { + let mut rdr = self.reader_with_entry(index).await?; + let mut buf = Vec::with_capacity(rdr.entry().uncompressed_size() as usize); + rdr.read_to_end_checked(&mut buf).await?; + Ok(buf) + } + } + + #[rustfmt::skip] #[cfg(any())] // FIXME: Gitのdiffを抑えるためだけに残してある状態 + const _: () = { struct AsyncVvmEntry { index: usize, entry: async_zip::ZipEntry, } - #[cfg(any())] // FIXME: Gitのdiffを抑えるためだけに残してある状態 #[derive(new)] struct AsyncVvmEntryReader<'a> { path: &'a Path, @@ -462,7 +505,6 @@ pub(crate) mod tokio { entry_map: HashMap, } - #[cfg(any())] // FIXME: Gitのdiffを抑えるためだけに残してある状態 impl<'a> AsyncVvmEntryReader<'a> { async fn open(path: &'a Path) -> LoadModelResult { let reader = async { @@ -521,48 +563,7 @@ pub(crate) mod tokio { }) } } - - type InferenceModelEntries<'manifest> = - (Option>,); - - struct InferenceModelEntry { - indices: EnumMap, - manifest: M, - } - - #[ext] - impl async_zip::base::read::seek::ZipFileReader> { - async fn from_file(path: &Path) -> anyhow::Result - where - Self: Sized, // 自明 - { - let zip = async_fs::File::open(path).await.with_context(|| { - // fs-errのと同じにする - format!("failed to open file `{}`", path.display()) - })?; - let zip = futures_util::io::BufReader::new(zip); - let zip = async_zip::base::read::seek::ZipFileReader::new(zip).await?; - Ok(zip) - } - - fn find_index(&self, filename: &str) -> anyhow::Result { - let (idx, _) = self - .file() - .entries() - .iter() - .enumerate() - .find(|(_, e)| e.filename().as_str().ok() == Some(filename)) - .with_context(|| "could not find `{filename}`")?; - Ok(idx) - } - - async fn read_file(&mut self, index: usize) -> anyhow::Result> { - let mut rdr = self.reader_with_entry(index).await?; - let mut buf = Vec::with_capacity(rdr.entry().uncompressed_size() as usize); - rdr.read_to_end_checked(&mut buf).await?; - Ok(buf) - } - } + }; } #[cfg(test)]