From cc8fd91c8691ca3fde7fa3bd245304ab8ad211c4 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 10 Mar 2022 11:44:59 -0600 Subject: [PATCH] Set event callbacks on pre-clone value to ensure that they remain alive. --- examples/clone_drop.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/clone_drop.rs b/examples/clone_drop.rs index 9c466ef..5b3dd0f 100644 --- a/examples/clone_drop.rs +++ b/examples/clone_drop.rs @@ -12,8 +12,6 @@ use tts::*; fn main() -> Result<(), Error> { env_logger::init(); let tts = Tts::default()?; - let mut tts_clone = tts.clone(); - drop(tts); if Tts::screen_reader_available() { println!("A screen reader is available on this platform."); } else { @@ -22,18 +20,20 @@ fn main() -> Result<(), Error> { let Features { utterance_callbacks, .. - } = tts_clone.supported_features(); + } = tts.supported_features(); if utterance_callbacks { - tts_clone.on_utterance_begin(Some(Box::new(|utterance| { + tts.on_utterance_begin(Some(Box::new(|utterance| { println!("Started speaking {:?}", utterance) })))?; - tts_clone.on_utterance_end(Some(Box::new(|utterance| { + tts.on_utterance_end(Some(Box::new(|utterance| { println!("Finished speaking {:?}", utterance) })))?; - tts_clone.on_utterance_stop(Some(Box::new(|utterance| { + tts.on_utterance_stop(Some(Box::new(|utterance| { println!("Stopped speaking {:?}", utterance) })))?; } + let mut tts_clone = tts.clone(); + drop(tts); let Features { is_speaking, .. } = tts_clone.supported_features(); if is_speaking { println!("Are we speaking? {}", tts_clone.is_speaking()?);