From 369bf23fa9f4a435ccf9384f45d9fb813073d69d Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 23 Dec 2019 08:03:24 -0600 Subject: [PATCH] Clippy, fmt, bump versions, and update repository links. --- speech-dispatcher-sys/Cargo.toml | 4 +- speech-dispatcher/Cargo.toml | 2 +- speech-dispatcher/examples/hello_world.rs | 17 ++- speech-dispatcher/src/lib.rs | 174 +++++++--------------- 4 files changed, 69 insertions(+), 128 deletions(-) diff --git a/speech-dispatcher-sys/Cargo.toml b/speech-dispatcher-sys/Cargo.toml index c1e4a38..e3ef79c 100644 --- a/speech-dispatcher-sys/Cargo.toml +++ b/speech-dispatcher-sys/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "speech-dispatcher-sys" -version = "0.4.1" +version = "0.4.2" authors = ["Nolan Darilek "] -repository = "https://gitlab.com/ndarilek/speech-dispatcher-sys" +repository = "https://gitlab.com/ndarilek/speech-dispatcher-rs" description = "speech-dispatcher system bindings" license = "LGPL-2.1" diff --git a/speech-dispatcher/Cargo.toml b/speech-dispatcher/Cargo.toml index 5ef33ba..2e77c16 100644 --- a/speech-dispatcher/Cargo.toml +++ b/speech-dispatcher/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "speech-dispatcher" -version = "0.4.1" +version = "0.4.2" authors = ["Nolan Darilek "] repository = "https://gitlab.com/ndarilek/speech-dispatcher-rs" description = "Rusty interface to the speech-dispatcher speech synthesis library" diff --git a/speech-dispatcher/examples/hello_world.rs b/speech-dispatcher/examples/hello_world.rs index 34acdb5..ea0e5a7 100644 --- a/speech-dispatcher/examples/hello_world.rs +++ b/speech-dispatcher/examples/hello_world.rs @@ -3,8 +3,16 @@ extern crate speech_dispatcher; use speech_dispatcher::*; fn main() { - let connection = speech_dispatcher::Connection::open("hello_world", "hello_world", "hello_world", Mode::Single); - connection.say(Priority::Important, format!("Hello, world at rate {}.", connection.get_voice_rate())); + let connection = speech_dispatcher::Connection::open( + "hello_world", + "hello_world", + "hello_world", + Mode::Single, + ); + connection.say( + Priority::Important, + format!("Hello, world at rate {}.", connection.get_voice_rate()), + ); connection.set_voice_rate(100); connection.say(Priority::Important, "This is faster."); connection.set_voice_rate(0); @@ -12,6 +20,9 @@ fn main() { connection.say(Priority::Important, "This is spelled."); connection.set_spelling(false); connection.set_punctuation(Punctuation::All); - connection.say(Priority::Important, "This statement, unlike others, has punctuation that is spoken!"); + connection.say( + Priority::Important, + "This statement, unlike others, has punctuation that is spoken!", + ); connection.set_punctuation(Punctuation::None); } diff --git a/speech-dispatcher/src/lib.rs b/speech-dispatcher/src/lib.rs index 291cc7c..db18dbb 100644 --- a/speech-dispatcher/src/lib.rs +++ b/speech-dispatcher/src/lib.rs @@ -64,11 +64,7 @@ pub enum CapitalLetters { } fn i32_to_bool(v: i32) -> bool { - if v == 1 { - true - } else { - false - } + v == 1 } impl Connection { @@ -78,20 +74,21 @@ impl Connection { user_name: S, mode: Mode, ) -> Connection { + let clientname = CString::new(client_name.into()).unwrap(); + let connectionname = CString::new(connection_name.into()).unwrap(); + let username = CString::new(user_name.into()).unwrap(); let connection = unsafe { spd_open( - CString::new(client_name.into()).unwrap().as_ptr(), - CString::new(connection_name.into()).unwrap().as_ptr(), - CString::new(user_name.into()).unwrap().as_ptr(), + clientname.as_ptr(), + connectionname.as_ptr(), + username.as_ptr(), mode as u32, ) }; - Connection { - connection: connection, - } + Connection { connection } } - pub fn open2>( + pub unsafe fn open2>( client_name: S, connection_name: S, user_name: S, @@ -101,17 +98,18 @@ impl Connection { ) -> Connection { let auto_spawn = if autospawn { 1 } else { 0 }; let error_result = vec![CString::new("").unwrap().into_raw()].as_mut_ptr(); - let connection = unsafe { - spd_open2( - CString::new(client_name.into()).unwrap().as_ptr(), - CString::new(connection_name.into()).unwrap().as_ptr(), - CString::new(user_name.into()).unwrap().as_ptr(), - mode as u32, - address, - auto_spawn, - error_result, - ) - }; + let clientname = CString::new(client_name.into()).unwrap(); + let connectionname = CString::new(connection_name.into()).unwrap(); + let username = CString::new(user_name.into()).unwrap(); + let connection = spd_open2( + clientname.as_ptr(), + connectionname.as_ptr(), + username.as_ptr(), + mode as u32, + address, + auto_spawn, + error_result, + ); Connection { connection } } @@ -120,24 +118,14 @@ impl Connection { } pub fn say>(&self, priority: Priority, text: S) -> bool { - let v = unsafe { - spd_say( - self.connection, - priority as u32, - CString::new(text.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(text.into()).unwrap(); + let v = unsafe { spd_say(self.connection, priority as u32, param.as_ptr()) }; i32_to_bool(v) } pub fn sayf>(&self, priority: Priority, format: S) -> bool { - let v = unsafe { - spd_sayf( - self.connection, - priority as u32, - CString::new(format.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(format.into()).unwrap(); + let v = unsafe { spd_sayf(self.connection, priority as u32, param.as_ptr()) }; i32_to_bool(v) } @@ -202,24 +190,14 @@ impl Connection { } pub fn key>(&self, priority: Priority, key_name: S) -> bool { - let v = unsafe { - spd_key( - self.connection, - priority as u32, - CString::new(key_name.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(key_name.into()).unwrap(); + let v = unsafe { spd_key(self.connection, priority as u32, param.as_ptr()) }; i32_to_bool(v) } pub fn char>(&self, priority: Priority, char: S) -> bool { - let v = unsafe { - spd_char( - self.connection, - priority as u32, - CString::new(char.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(char.into()).unwrap(); + let v = unsafe { spd_char(self.connection, priority as u32, param.as_ptr()) }; i32_to_bool(v) } @@ -229,13 +207,8 @@ impl Connection { } pub fn sound_icon>(&self, priority: Priority, icon_name: S) -> bool { - let v = unsafe { - spd_char( - self.connection, - priority as u32, - CString::new(icon_name.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(icon_name.into()).unwrap(); + let v = unsafe { spd_char(self.connection, priority as u32, param.as_ptr()) }; i32_to_bool(v) } @@ -270,33 +243,20 @@ impl Connection { } pub fn set_synthesis_voice>(&self, voice_name: S) -> bool { - let v = unsafe { - spd_set_synthesis_voice( - self.connection, - CString::new(voice_name.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(voice_name.into()).unwrap(); + let v = unsafe { spd_set_synthesis_voice(self.connection, param.as_ptr()) }; i32_to_bool(v) } pub fn set_synthesis_voice_all>(&self, voice_name: S) -> bool { - let v = unsafe { - spd_set_synthesis_voice_all( - self.connection, - CString::new(voice_name.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(voice_name.into()).unwrap(); + let v = unsafe { spd_set_synthesis_voice_all(self.connection, param.as_ptr()) }; i32_to_bool(v) } pub fn set_synthesis_voice_uid>(&self, voice_name: S, target_uid: u32) -> bool { - let v = unsafe { - spd_set_synthesis_voice_uid( - self.connection, - CString::new(voice_name.into()).unwrap().as_ptr(), - target_uid, - ) - }; + let param = CString::new(voice_name.into()).unwrap(); + let v = unsafe { spd_set_synthesis_voice_uid(self.connection, param.as_ptr(), target_uid) }; i32_to_bool(v) } @@ -316,13 +276,9 @@ impl Connection { } pub fn set_notification>(&self, notification: Notification, state: S) -> bool { - let v = unsafe { - spd_set_notification( - self.connection, - notification as u32, - CString::new(state.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(state.into()).unwrap(); + let v = + unsafe { spd_set_notification(self.connection, notification as u32, param.as_ptr()) }; i32_to_bool(v) } @@ -450,33 +406,20 @@ impl Connection { } pub fn set_language>(&self, language: S) -> bool { - let v = unsafe { - spd_set_language( - self.connection, - CString::new(language.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(language.into()).unwrap(); + let v = unsafe { spd_set_language(self.connection, param.as_ptr()) }; i32_to_bool(v) } pub fn set_language_all>(&self, language: S) -> bool { - let v = unsafe { - spd_set_language_all( - self.connection, - CString::new(language.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(language.into()).unwrap(); + let v = unsafe { spd_set_language_all(self.connection, param.as_ptr()) }; i32_to_bool(v) } pub fn set_language_uid>(&self, language: S, target_uid: u32) -> bool { - let v = unsafe { - spd_set_language_uid( - self.connection, - CString::new(language.into()).unwrap().as_ptr(), - target_uid, - ) - }; + let param = CString::new(language.into()).unwrap(); + let v = unsafe { spd_set_language_uid(self.connection, param.as_ptr(), target_uid) }; i32_to_bool(v) } @@ -486,22 +429,14 @@ impl Connection { } pub fn set_output_module>(&self, output_module: S) -> bool { - let v = unsafe { - spd_set_output_module( - self.connection, - CString::new(output_module.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(output_module.into()).unwrap(); + let v = unsafe { spd_set_output_module(self.connection, param.as_ptr()) }; i32_to_bool(v) } pub fn set_output_module_all>(&self, output_module: S) -> bool { - let v = unsafe { - spd_set_output_module_all( - self.connection, - CString::new(output_module.into()).unwrap().as_ptr(), - ) - }; + let param = CString::new(output_module.into()).unwrap(); + let v = unsafe { spd_set_output_module_all(self.connection, param.as_ptr()) }; i32_to_bool(v) } @@ -510,13 +445,8 @@ impl Connection { output_module: S, target_uid: u32, ) -> bool { - let v = unsafe { - spd_set_output_module_uid( - self.connection, - CString::new(output_module.into()).unwrap().as_ptr(), - target_uid, - ) - }; + let param = CString::new(output_module.into()).unwrap(); + let v = unsafe { spd_set_output_module_uid(self.connection, param.as_ptr(), target_uid) }; i32_to_bool(v) } }