mirror of https://github.com/ndarilek/tts-rs.git
Switch `Arc` to `Rc` to appease Clippy.
This commit is contained in:
parent
96a5209a9f
commit
07edc20861
25
src/lib.rs
25
src/lib.rs
|
@ -14,9 +14,10 @@ use std::collections::HashMap;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::rc::Rc;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::string::FromUtf16Error;
|
use std::string::FromUtf16Error;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Mutex;
|
||||||
use std::{boxed::Box, sync::RwLock};
|
use std::{boxed::Box, sync::RwLock};
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
@ -258,7 +259,7 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Tts(Arc<RwLock<Box<dyn Backend>>>);
|
pub struct Tts(Rc<RwLock<Box<dyn Backend>>>);
|
||||||
|
|
||||||
unsafe impl Send for Tts {}
|
unsafe impl Send for Tts {}
|
||||||
|
|
||||||
|
@ -271,18 +272,18 @@ impl Tts {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
Backends::SpeechDispatcher => {
|
Backends::SpeechDispatcher => {
|
||||||
let tts = backends::SpeechDispatcher::new()?;
|
let tts = backends::SpeechDispatcher::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
Backends::Web => {
|
Backends::Web => {
|
||||||
let tts = backends::Web::new()?;
|
let tts = backends::Web::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
#[cfg(all(windows, feature = "tolk"))]
|
#[cfg(all(windows, feature = "tolk"))]
|
||||||
Backends::Tolk => {
|
Backends::Tolk => {
|
||||||
let tts = backends::Tolk::new();
|
let tts = backends::Tolk::new();
|
||||||
if let Some(tts) = tts {
|
if let Some(tts) = tts {
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::NoneError)
|
Err(Error::NoneError)
|
||||||
}
|
}
|
||||||
|
@ -290,20 +291,20 @@ impl Tts {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backends::WinRt => {
|
Backends::WinRt => {
|
||||||
let tts = backends::WinRt::new()?;
|
let tts = backends::WinRt::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
Backends::AppKit => Ok(Tts(Arc::new(RwLock::new(Box::new(
|
Backends::AppKit => Ok(Tts(Rc::new(RwLock::new(
|
||||||
backends::AppKit::new()?
|
Box::new(backends::AppKit::new()?),
|
||||||
))))),
|
)))),
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
Backends::AvFoundation => Ok(Tts(Arc::new(RwLock::new(Box::new(
|
Backends::AvFoundation => Ok(Tts(Rc::new(RwLock::new(Box::new(
|
||||||
backends::AvFoundation::new()?,
|
backends::AvFoundation::new()?,
|
||||||
))))),
|
))))),
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
Backends::Android => {
|
Backends::Android => {
|
||||||
let tts = backends::Android::new()?;
|
let tts = backends::Android::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Ok(backend) = backend {
|
if let Ok(backend) = backend {
|
||||||
|
@ -640,7 +641,7 @@ impl Tts {
|
||||||
|
|
||||||
impl Drop for Tts {
|
impl Drop for Tts {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if Arc::strong_count(&self.0) <= 1 {
|
if Rc::strong_count(&self.0) <= 1 {
|
||||||
if let Some(id) = self.0.read().unwrap().id() {
|
if let Some(id) = self.0.read().unwrap().id() {
|
||||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||||
callbacks.remove(&id);
|
callbacks.remove(&id);
|
||||||
|
|
Loading…
Reference in New Issue