Extend lifetimes on WhisperState and WhisperToken

This commit is contained in:
Niko 2025-09-29 13:28:58 -07:00
parent 4e2c466e79
commit 31c1527abe
No known key found for this signature in database
2 changed files with 8 additions and 8 deletions

View file

@ -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<Cow<'_, str>, WhisperError> {
pub fn to_str_lossy(&self) -> Result<Cow<'a, str>, WhisperError> {
Ok(self.to_raw_cstr()?.to_string_lossy())
}

View file

@ -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<Cow<'_, str>, WhisperError> {
pub fn to_str_lossy(&self) -> Result<Cow<'b, str>, WhisperError> {
Ok(self.to_raw_cstr()?.to_string_lossy())
}
}