refactor: delete map for State and expose struct with lifetime

This commit is contained in:
Yuniru Yuni 2023-04-25 22:48:45 +09:00
parent bc5fd8ffcb
commit 6169229e60
No known key found for this signature in database
GPG key ID: 33E3309A80C571CD
2 changed files with 101 additions and 112 deletions

View file

@ -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 {