Skip to content

Commit

Permalink
futures_lite::future::block_on.block_on()として使えるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Sep 10, 2024
1 parent f580e47 commit 955bea5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions crates/voicevox_core/src/future.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::future::Future;

use easy_ext::ext;

/// `futures_lite::future::block_on`を、[pollster]のように`.block_on()`という形で使えるようにする。
///
/// [pollster]: https://docs.rs/crate/pollster
#[ext(FutureExt)]
impl<F: Future> F {
pub(crate) fn block_on(self) -> Self::Output
where
Self: Sized,
{
futures_lite::future::block_on(self)
}
}
1 change: 1 addition & 0 deletions crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mod devices;
/// cbindgen:ignore
mod engine;
mod error;
mod future;
mod infer;
mod macros;
mod manifest;
Expand Down
8 changes: 4 additions & 4 deletions crates/voicevox_core/src/voice_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ pub(crate) mod blocking {
use uuid::Uuid;

use crate::{
asyncs::Unstoppable, error::LoadModelResult, infer::domains::InferenceDomainMap,
VoiceModelMeta,
asyncs::Unstoppable, error::LoadModelResult, future::FutureExt as _,
infer::domains::InferenceDomainMap, VoiceModelMeta,
};

use super::{Inner, ModelBytesWithInnerVoiceIdsByDomain, VoiceModelHeader, VoiceModelId};
Expand All @@ -410,12 +410,12 @@ pub(crate) mod blocking {
pub(crate) fn read_inference_models(
&self,
) -> LoadModelResult<InferenceDomainMap<ModelBytesWithInnerVoiceIdsByDomain>> {
futures_lite::future::block_on(self.0.read_inference_models())
self.0.read_inference_models().block_on()
}

/// VVMファイルから`VoiceModel`をコンストラクトする。
pub fn from_path(path: impl AsRef<Path>) -> crate::Result<Self> {
futures_lite::future::block_on(Inner::from_path(path)).map(Self)
Inner::from_path(path).block_on().map(Self)
}

/// ID。
Expand Down

0 comments on commit 955bea5

Please sign in to comment.