Skip to content

Commit

Permalink
Avoid allocating in /modes
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Mar 5, 2024
1 parent 15a07b9 commit eae8b6c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,29 @@ impl TTSMode {
Self::gCloud => Some(4.0),
}
}
}

impl Display for TTSMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
fn as_str(self) -> &'static str {
match self {
Self::gTTS => "gTTS",
Self::Polly => "Polly",
Self::eSpeak => "eSpeak",
Self::gCloud => "gCloud",
})
}
}
}

impl Display for TTSMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}

impl serde::Serialize for TTSMode {
fn serialize<S>(&self, serializer: S) -> std::prelude::v1::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}

Expand Down Expand Up @@ -361,10 +374,10 @@ async fn main() -> Result<()> {
"/modes",
get(|| async {
axum::Json([
TTSMode::gTTS.to_string(),
TTSMode::Polly.to_string(),
TTSMode::eSpeak.to_string(),
TTSMode::gCloud.to_string(),
TTSMode::gTTS,
TTSMode::Polly,
TTSMode::eSpeak,
TTSMode::gCloud,
])
}),
);
Expand Down

0 comments on commit eae8b6c

Please sign in to comment.