Skip to main content

FallbackEstimator

Struct FallbackEstimator 

Source
pub struct FallbackEstimator { /* private fields */ }
Expand description

spc_011-C-01: real-BPE-backed counter, the production default. CharApproxCounter’s char/4 divisor only holds for English text — on CJK-heavy text it underestimates real BPE counts by 40-70% (its own doc comment claims “~0.5 tokens/char” for CJK, but the implementation applies the same 0.25 tokens/char divisor to every script). This wraps deepstrike-tokenizer’s real cl100k BPE tokenizer (previously an orphaned crate — not a workspace member, zero call sites anywhere) and adds a fixed margin on top. That only guarantees a value above the selected cl100k_base estimate; it does not prove that the result is conservative for every provider model. Native Anthropic/Gemini token counts take precedence where callers explicitly request them.

Implementations§

Source§

impl FallbackEstimator

Source

pub fn new(backend: TokenizerBackend, safety_margin: f64) -> Self

Trait Implementations§

Source§

impl Default for FallbackEstimator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TokenCounter for FallbackEstimator

Source§

fn count(&self, text: &str) -> u32

Count tokens in a UTF-8 string.
Source§

fn truncate<'a>(&self, text: &'a str, max_tokens: u32) -> &'a str

Return the longest prefix of text that fits within max_tokens. The returned slice is always a valid UTF-8 prefix of text.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.