Change token_to_str to return &str instead of String

This commit is contained in:
0/0 2023-05-05 01:33:06 +00:00 committed by GitHub
parent a7caf1b96a
commit d77108fca6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -306,14 +306,14 @@ impl WhisperContext {
/// * token_id: ID of the token.
///
/// # Returns
/// Ok(String) on success, Err(WhisperError) on failure.
/// Ok(&str) on success, Err(WhisperError) on failure.
///
/// # C++ equivalent
/// `const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token)`
pub fn token_to_str(&self, token_id: WhisperToken) -> Result<String, WhisperError> {
pub fn token_to_str(&self, token_id: WhisperToken) -> Result<&str, WhisperError> {
let c_str = self.token_to_cstr(token_id)?;
let r_str = c_str.to_str()?;
Ok(r_str.to_string())
Ok(r_str)
}
/// Convert a token ID to a &CStr.