Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Mar 10, 2024
1 parent e46cbd4 commit 0403753
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
15 changes: 11 additions & 4 deletions crates/voicevox_core/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ pub(crate) trait InferenceRuntime: 'static {
}

pub(crate) trait InferenceDomainGroup: Sized {
type Map<A: InferenceDomainAssociation>: InferenceDomainMap<A, Group = Self>;
type Map<A: InferenceDomainAssociation>: InferenceDomainMap<Group = Self, Association = A>;
}

pub(crate) trait InferenceDomainMap<A: InferenceDomainAssociation> {
pub(crate) trait InferenceDomainMap {
type Group: InferenceDomainGroup;
type Association: InferenceDomainAssociation;

fn any(&self, p: impl InferenceDomainAssociationTargetPredicate<InputAssociation = A>) -> bool;
fn any(
&self,
p: impl InferenceDomainAssociationTargetPredicate<InputAssociation = Self::Association>,
) -> bool;

fn try_ref_map<
F: InferenceDomainAssociationTargetFunction<Group = Self::Group, InputAssociation = A>,
F: InferenceDomainAssociationTargetFunction<
Group = Self::Group,
InputAssociation = Self::Association,
>,
>(
&self,
f: F,
Expand Down
13 changes: 10 additions & 3 deletions crates/voicevox_core/src/infer/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ pub(crate) struct InferenceDomainMapImpl<A: InferenceDomainAssociation> {
pub(crate) talk: A::Target<TalkDomain>,
}

impl<A: InferenceDomainAssociation> InferenceDomainMap<A> for InferenceDomainMapImpl<A> {
impl<A: InferenceDomainAssociation> InferenceDomainMap for InferenceDomainMapImpl<A> {
type Group = InferenceDomainGroupImpl;
type Association = A;

fn any(&self, p: impl InferenceDomainAssociationTargetPredicate<InputAssociation = A>) -> bool {
fn any(
&self,
p: impl InferenceDomainAssociationTargetPredicate<InputAssociation = Self::Association>,
) -> bool {
p.test(&self.talk)
}

fn try_ref_map<
F: InferenceDomainAssociationTargetFunction<Group = Self::Group, InputAssociation = A>,
F: InferenceDomainAssociationTargetFunction<
Group = Self::Group,
InputAssociation = Self::Association,
>,
>(
&self,
f: F,
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/infer/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<R: InferenceRuntime, G: InferenceDomainGroup> LoadedModels<R, G> {
.unwrap();
panic!(
"missing session set for `{type_name}` (should be checked in \
`ensure_acceptable`)",
`ensure_acceptable` and `ids_for`)",
);
});
session_set.get()
Expand Down
1 change: 1 addition & 0 deletions crates/voicevox_core_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use syn::parse_macro_input;
///
/// impl InferenceDomain for TalkDomain {
/// type Operation = TalkOperation;
/// // ...
/// }
///
/// #[derive(Clone, Copy, Enum, InferenceOperation)]
Expand Down

0 comments on commit 0403753

Please sign in to comment.