From 31c1527abe80a3ed80a75959a642b8e603cca1ee Mon Sep 17 00:00:00 2001 From: Niko Date: Mon, 29 Sep 2025 13:28:58 -0700 Subject: [PATCH] Extend lifetimes on `WhisperState` and `WhisperToken` --- src/whisper_state/segment.rs | 8 ++++---- src/whisper_state/token.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/whisper_state/segment.rs b/src/whisper_state/segment.rs index 7e41b93..4795b00 100644 --- a/src/whisper_state/segment.rs +++ b/src/whisper_state/segment.rs @@ -105,7 +105,7 @@ impl<'a> WhisperSegment<'a> { } } - fn to_raw_cstr(&self) -> Result<&CStr, WhisperError> { + fn to_raw_cstr(&self) -> Result<&'a CStr, WhisperError> { let ret = unsafe { whisper_rs_sys::whisper_full_get_segment_text_from_state( self.state.ptr, @@ -126,7 +126,7 @@ impl<'a> WhisperSegment<'a> { /// /// # C++ equivalent /// `const char * whisper_full_get_segment_text(struct whisper_context * ctx, int i_segment)` - pub fn to_bytes(&self) -> Result<&[u8], WhisperError> { + pub fn to_bytes(&self) -> Result<&'a [u8], WhisperError> { Ok(self.to_raw_cstr()?.to_bytes()) } @@ -138,7 +138,7 @@ impl<'a> WhisperSegment<'a> { /// /// # C++ equivalent /// `const char * whisper_full_get_segment_text(struct whisper_context * ctx, int i_segment)` - pub fn to_str(&self) -> Result<&str, WhisperError> { + pub fn to_str(&self) -> Result<&'a str, WhisperError> { Ok(self.to_raw_cstr()?.to_str()?) } @@ -154,7 +154,7 @@ impl<'a> WhisperSegment<'a> { /// /// # C++ equivalent /// `const char * whisper_full_get_segment_text(struct whisper_context * ctx, int i_segment)` - pub fn to_str_lossy(&self) -> Result, WhisperError> { + pub fn to_str_lossy(&self) -> Result, WhisperError> { Ok(self.to_raw_cstr()?.to_string_lossy()) } diff --git a/src/whisper_state/token.rs b/src/whisper_state/token.rs index c57435d..46d22a0 100644 --- a/src/whisper_state/token.rs +++ b/src/whisper_state/token.rs @@ -66,7 +66,7 @@ impl<'a, 'b> WhisperToken<'a, 'b> { } } - fn to_raw_cstr(&self) -> Result<&CStr, WhisperError> { + fn to_raw_cstr(&self) -> Result<&'b CStr, WhisperError> { let ret = unsafe { whisper_rs_sys::whisper_full_get_token_text_from_state( self.segment.get_state().ctx.ctx, @@ -92,7 +92,7 @@ impl<'a, 'b> WhisperToken<'a, 'b> { /// /// # C++ equivalent /// `const char * whisper_full_get_token_text(struct whisper_context * ctx, int i_segment, int i_token)` - pub fn to_bytes(&self) -> Result<&[u8], WhisperError> { + pub fn to_bytes(&self) -> Result<&'b [u8], WhisperError> { Ok(self.to_raw_cstr()?.to_bytes()) } @@ -104,7 +104,7 @@ impl<'a, 'b> WhisperToken<'a, 'b> { /// /// # C++ equivalent /// `const char * whisper_full_get_token_text(struct whisper_context * ctx, int i_segment, int i_token)` - pub fn to_str(&self) -> Result<&str, WhisperError> { + pub fn to_str(&self) -> Result<&'b str, WhisperError> { Ok(self.to_raw_cstr()?.to_str()?) } @@ -120,7 +120,7 @@ impl<'a, 'b> WhisperToken<'a, 'b> { /// /// # C++ equivalent /// `const char * whisper_full_get_token_text(struct whisper_context * ctx, int i_segment, int i_token)` - pub fn to_str_lossy(&self) -> Result, WhisperError> { + pub fn to_str_lossy(&self) -> Result, WhisperError> { Ok(self.to_raw_cstr()?.to_string_lossy()) } }