refactor: delete map for State and expose struct with lifetime
This commit is contained in:
parent
bc5fd8ffcb
commit
6169229e60
2 changed files with 101 additions and 112 deletions
|
|
@ -1,13 +1,16 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
/// Rustified pointer to a Whisper state.
|
||||
#[derive(Debug)]
|
||||
pub struct WhisperState {
|
||||
pub struct WhisperState<'a> {
|
||||
ptr: *mut whisper_rs_sys::whisper_state,
|
||||
_phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
unsafe impl Send for WhisperState {}
|
||||
unsafe impl Sync for WhisperState {}
|
||||
unsafe impl<'a> Send for WhisperState<'a> {}
|
||||
unsafe impl<'a> Sync for WhisperState<'a> {}
|
||||
|
||||
impl Drop for WhisperState {
|
||||
impl<'a> Drop for WhisperState<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
whisper_rs_sys::whisper_free_state(self.ptr);
|
||||
|
|
@ -15,9 +18,12 @@ impl Drop for WhisperState {
|
|||
}
|
||||
}
|
||||
|
||||
impl WhisperState {
|
||||
pub(crate) unsafe fn new(ptr: *mut whisper_rs_sys::whisper_state) -> Self {
|
||||
Self { ptr }
|
||||
impl<'a> WhisperState<'a> {
|
||||
pub(crate) fn new(ptr: *mut whisper_rs_sys::whisper_state) -> Self {
|
||||
Self {
|
||||
ptr,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn as_ptr(&self) -> *mut whisper_rs_sys::whisper_state {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue