Merge pull request #162 from thewh1teagle/feat/add-clone-to-params
feat: add clone to params
This commit is contained in:
commit
2ee68ff56c
1 changed files with 6 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue