Skip to content

feat: [Rust] UserDictからIndexMapinto可能にする #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions crates/voicevox_core/src/user_dict/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ impl<A: Async> Inner<A> {
}
}

impl<A: Async> From<Inner<A>> for IndexMap<Uuid, UserDictWord> {
fn from(inner: Inner<A>) -> Self {
inner.words.into_inner().unwrap_or_else(|e| panic!("{e}"))
}
}

impl<A: Async> From<&'_ Inner<A>> for IndexMap<Uuid, UserDictWord> {
fn from(inner: &'_ Inner<A>) -> Self {
inner.with_words(|words| words.clone())
}
}

#[ext]
impl<A: Async> A {
async fn fs_err_read(path: impl AsRef<Path>) -> anyhow::Result<Vec<u8>> {
Expand All @@ -111,6 +123,7 @@ impl<A: Async> A {
pub(crate) mod blocking {
use std::path::Path;

use duplicate::duplicate_item;
use indexmap::IndexMap;
use uuid::Uuid;

Expand Down Expand Up @@ -186,11 +199,29 @@ pub(crate) mod blocking {
self.0.to_mecab_format()
}
}

impl From<self::UserDict> for IndexMap<Uuid, UserDictWord> {
fn from(dict: self::UserDict) -> Self {
dict.0.into()
}
}

#[duplicate_item(
T;
[ &'_ self::UserDict ];
[ &'_ mut self::UserDict ];
)]
impl From<T> for IndexMap<Uuid, UserDictWord> {
fn from(dict: T) -> Self {
(&dict.0).into()
}
}
}

pub(crate) mod nonblocking {
use std::path::Path;

use duplicate::duplicate_item;
use indexmap::IndexMap;
use uuid::Uuid;

Expand Down Expand Up @@ -264,4 +295,21 @@ pub(crate) mod nonblocking {
self.0.to_mecab_format()
}
}

impl From<self::UserDict> for IndexMap<Uuid, UserDictWord> {
fn from(dict: self::UserDict) -> Self {
dict.0.into()
}
}

#[duplicate_item(
T;
[ &'_ self::UserDict ];
[ &'_ mut self::UserDict ];
)]
impl From<T> for IndexMap<Uuid, UserDictWord> {
fn from(dict: T) -> Self {
(&dict.0).into()
}
}
}