feat: add clone to params

This commit is contained in:
thewh1teagle 2024-07-10 02:37:33 +03:00
parent f1030ef762
commit a5f516acfd
No known key found for this signature in database
GPG key ID: F7BFC3A4192804E4

View file

@ -1,6 +1,7 @@
use crate::whisper_grammar::WhisperGrammarElement;
use std::ffi::{c_char, c_float, c_int, CString};
use std::marker::PhantomData;
use std::sync::Arc;
use whisper_rs_sys::whisper_token;
#[derive(Debug, Clone)]
@ -31,14 +32,15 @@ pub struct SegmentCallbackData {
type SegmentCallbackFn = Box<dyn FnMut(SegmentCallbackData)>;
#[derive(Clone)]
pub struct FullParams<'a, 'b> {
pub(crate) fp: whisper_rs_sys::whisper_full_params,
phantom_lang: PhantomData<&'a str>,
phantom_tokens: PhantomData<&'b [c_int]>,
grammar: Option<Vec<whisper_rs_sys::whisper_grammar_element>>,
progess_callback_safe: Option<Box<dyn FnMut(i32)>>,
abort_callback_safe: Option<Box<dyn FnMut() -> bool>>,
segment_calllback_safe: Option<SegmentCallbackFn>,
progess_callback_safe: Option<Arc<Box<dyn FnMut(i32)>>>,
abort_callback_safe: Option<Arc<Box<dyn FnMut() -> bool>>>,
segment_calllback_safe: Option<Arc<SegmentCallbackFn>>,
}
impl<'a, 'b> FullParams<'a, 'b> {
@ -588,7 +590,7 @@ impl<'a, 'b> FullParams<'a, 'b> {
self.fp.progress_callback = Some(trampoline::<F>);
self.fp.progress_callback_user_data = &mut closure as *mut F as *mut c_void;
// store the closure internally to make sure that the pointer above remains valid
self.progess_callback_safe = Some(Box::new(closure));
self.progess_callback_safe = Some(Arc::new(Box::new(closure)));
}
None => {
self.fp.progress_callback = None;