From c222c087b289e403b743f892764969e5c0551c9e Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 30 Mar 2022 10:18:22 -0500 Subject: [PATCH] cargo fmt --- examples/hello_world.rs | 4 ++-- src/backends/appkit.rs | 4 ++-- src/backends/av_foundation.rs | 11 +++++---- src/backends/av_foundation/voices.rs | 34 +++++++++++++++------------- src/backends/speech_dispatcher.rs | 4 ++-- src/backends/tolk.rs | 4 ++-- src/backends/web.rs | 4 ++-- src/backends/winrt.rs | 4 ++-- src/lib.rs | 8 +++---- src/voices.rs | 1 - 10 files changed, 41 insertions(+), 37 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 18f5869..3885ede 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -77,11 +77,11 @@ fn main() -> Result<(), Error> { let voices_list = tts.list_voices(); println!("Available voices:\n==="); for v in voices_list.iter() { - println!("{}",v); + println!("{}", v); tts.set_voice(v)?; println!("voice set"); println!("{}", tts.voice()?); - tts.speak(v,false)?; + tts.speak(v, false)?; } tts.set_voice(original_voice)?; } diff --git a/src/backends/appkit.rs b/src/backends/appkit.rs index 44658d7..389418d 100644 --- a/src/backends/appkit.rs +++ b/src/backends/appkit.rs @@ -201,7 +201,7 @@ impl Backend for AppKit { Ok(is_speaking != NO as i8) } - fn voice(&self) -> Result { + fn voice(&self) -> Result { unimplemented!() } @@ -209,7 +209,7 @@ impl Backend for AppKit { unimplemented!() } - fn set_voice(&mut self, voice: &str) -> Result<(),Error> { + fn set_voice(&mut self, voice: &str) -> Result<(), Error> { unimplemented!() } } diff --git a/src/backends/av_foundation.rs b/src/backends/av_foundation.rs index fcedf6f..9e79a47 100644 --- a/src/backends/av_foundation.rs +++ b/src/backends/av_foundation.rs @@ -9,8 +9,8 @@ use log::{info, trace}; use objc::runtime::{Object, Sel}; use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl}; -use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS}; use crate::voices::Backend as VoiceBackend; +use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS}; mod voices; use voices::*; @@ -280,15 +280,18 @@ impl Backend for AvFoundation { Ok(is_speaking != NO as i8) } - fn voice(&self) -> Result { + fn voice(&self) -> Result { Ok(self.voice.id()) } fn list_voices(&self) -> Vec { - AVSpeechSynthesisVoice::list().iter().map(|v| {v.id()}).collect() + AVSpeechSynthesisVoice::list() + .iter() + .map(|v| v.id()) + .collect() } - fn set_voice(&mut self, voice: &str) -> Result<(),Error> { + fn set_voice(&mut self, voice: &str) -> Result<(), Error> { self.voice = AVSpeechSynthesisVoice::new(); Ok(()) } diff --git a/src/backends/av_foundation/voices.rs b/src/backends/av_foundation/voices.rs index e6ae49a..836adc7 100644 --- a/src/backends/av_foundation/voices.rs +++ b/src/backends/av_foundation/voices.rs @@ -1,25 +1,24 @@ - +use cocoa_foundation::base::{id, nil}; +use cocoa_foundation::foundation::NSString; +use core_foundation::array::CFArray; +use core_foundation::string::CFString; use objc::runtime::*; use objc::*; -use core_foundation::array::CFArray; -use cocoa_foundation::foundation::NSString; -use cocoa_foundation::base::{nil,id}; -use core_foundation::string::CFString; use crate::backends::AvFoundation; use crate::voices; use crate::voices::Gender; -#[derive(Copy,Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub(crate) struct AVSpeechSynthesisVoice(*const Object); impl AVSpeechSynthesisVoice { pub fn new() -> Self { let voice: *const Object; - unsafe{ + unsafe { voice = msg_send![class!(AVSpeechSynthesisVoice), new]; }; - AVSpeechSynthesisVoice{0:voice} + AVSpeechSynthesisVoice { 0: voice } } } @@ -35,19 +34,22 @@ impl voices::Backend for AVSpeechSynthesisVoice { } fn list() -> Vec { - let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]}; - voices.iter().map(|v| { - AVSpeechSynthesisVoice{0: *v as *const Object} - }).collect() + let voices: CFArray = unsafe { msg_send![class!(AVSpeechSynthesisVoice), speechVoices] }; + voices + .iter() + .map(|v| AVSpeechSynthesisVoice { + 0: *v as *const Object, + }) + .collect() } fn name(self) -> String { - let name: CFString = unsafe{msg_send![self.0, name]}; + let name: CFString = unsafe { msg_send![self.0, name] }; name.to_string() } fn gender(self) -> Gender { - let gender: i64 = unsafe{ msg_send![self.0, gender] }; + let gender: i64 = unsafe { msg_send![self.0, gender] }; match gender { 1 => Gender::Male, 2 => Gender::Female, @@ -56,12 +58,12 @@ impl voices::Backend for AVSpeechSynthesisVoice { } fn id(self) -> String { - let identifier: CFString = unsafe{msg_send![self.0, identifier]}; + let identifier: CFString = unsafe { msg_send![self.0, identifier] }; identifier.to_string() } fn language(self) -> voices::LanguageIdentifier { - let lang: CFString = unsafe{msg_send![self.0, language]}; + let lang: CFString = unsafe { msg_send![self.0, language] }; lang.to_string().parse().unwrap() } } diff --git a/src/backends/speech_dispatcher.rs b/src/backends/speech_dispatcher.rs index 15ec937..4dc1565 100644 --- a/src/backends/speech_dispatcher.rs +++ b/src/backends/speech_dispatcher.rs @@ -181,7 +181,7 @@ impl Backend for SpeechDispatcher { Ok(*is_speaking) } - fn voice(&self) -> Result { + fn voice(&self) -> Result { unimplemented!() } @@ -189,7 +189,7 @@ impl Backend for SpeechDispatcher { unimplemented!() } - fn set_voice(&mut self, voice: &str) -> Result<(),Error> { + fn set_voice(&mut self, voice: &str) -> Result<(), Error> { unimplemented!() } } diff --git a/src/backends/tolk.rs b/src/backends/tolk.rs index e324525..45e2f0b 100644 --- a/src/backends/tolk.rs +++ b/src/backends/tolk.rs @@ -109,7 +109,7 @@ impl Backend for Tolk { unimplemented!() } - fn voice(&self) -> Result { + fn voice(&self) -> Result { unimplemented!() } @@ -117,7 +117,7 @@ impl Backend for Tolk { unimplemented!() } - fn set_voice(&mut self, voice: &str) -> Result<(),Error> { + fn set_voice(&mut self, voice: &str) -> Result<(), Error> { unimplemented!() } } diff --git a/src/backends/web.rs b/src/backends/web.rs index 3bc3c2e..57a8af3 100644 --- a/src/backends/web.rs +++ b/src/backends/web.rs @@ -198,7 +198,7 @@ impl Backend for Web { } } - fn voice(&self) -> Result { + fn voice(&self) -> Result { unimplemented!() } @@ -206,7 +206,7 @@ impl Backend for Web { unimplemented!() } - fn set_voice(&mut self, voice: &str) -> Result<(),Error> { + fn set_voice(&mut self, voice: &str) -> Result<(), Error> { unimplemented!() } } diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index c573766..dbacbc6 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -291,7 +291,7 @@ impl Backend for WinRt { Ok(!utterances.is_empty()) } - fn voice(&self) -> Result { + fn voice(&self) -> Result { unimplemented!() } @@ -299,7 +299,7 @@ impl Backend for WinRt { unimplemented!() } - fn set_voice(&mut self, voice: &str) -> Result<(),Error> { + fn set_voice(&mut self, voice: &str) -> Result<(), Error> { unimplemented!() } } diff --git a/src/lib.rs b/src/lib.rs index 82ad5bb..72e1ecd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,7 +232,7 @@ pub trait Backend: Clone { fn is_speaking(&self) -> Result; fn voice(&self) -> Result; fn list_voices(&self) -> Vec; - fn set_voice(&mut self, voice: &str) -> Result<(),Error>; + fn set_voice(&mut self, voice: &str) -> Result<(), Error>; } #[derive(Default)] @@ -569,9 +569,9 @@ impl Tts { } /** - * Return the current speaking voice. + * Return the current speaking voice. */ - pub fn voice(&self) -> Result { + pub fn voice(&self) -> Result { let Features { voices, .. } = self.supported_features(); if voices { self.0.read().unwrap().voice() @@ -583,7 +583,7 @@ impl Tts { /** * Set speaking voice. */ - pub fn set_voice>(&mut self, voice: S) -> Result<(),Error> { + pub fn set_voice>(&mut self, voice: S) -> Result<(), Error> { let Features { voices: voices_feature, .. diff --git a/src/voices.rs b/src/voices.rs index 8ca927d..f4b3490 100644 --- a/src/voices.rs +++ b/src/voices.rs @@ -1,4 +1,3 @@ - pub use unic_langid::LanguageIdentifier; pub enum Gender {