From 7e46c91cbd8c3c6392a1b4a52f5a7134ee520f7d Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 13 Aug 2025 00:53:44 -0700 Subject: [PATCH] Add docs to `get_token` and its unchecked variant --- src/whisper_state/segment.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/whisper_state/segment.rs b/src/whisper_state/segment.rs index 50f2e4e..1ed6273 100644 --- a/src/whisper_state/segment.rs +++ b/src/whisper_state/segment.rs @@ -153,13 +153,18 @@ impl<'a> WhisperSegment<'a> { token_idx >= 0 && token_idx < self.token_count } + /// Get the token at the specified index. Returns `None` if out of bounds for this state. pub fn get_token(&self, token: c_int) -> Option> { self.token_in_bounds(token) + // SAFETY: we've just asserted that this token is in bounds .then(|| unsafe { WhisperToken::new_unchecked(self, token) }) } + /// The same as [`Self::get_token`] but without any bounds check. + /// /// # Safety /// You must ensure `token` is in bounds for this [`WhisperSegment`]. + /// If it is not, this is immediate Undefined Behaviour. pub unsafe fn get_token_unchecked(&self, token: c_int) -> WhisperToken<'_, '_> { WhisperToken::new_unchecked(self, token) }