pub struct TokenizerRegistry { /* private fields */ }Expand description
Registry for managing tokenizers keyed by UUID
Features:
- Thread-safe concurrent access using DashMap
- Per-key locking to prevent duplicate loading
- Lookup by UUID (primary) or name (secondary index)
Implementations§
Source§impl TokenizerRegistry
impl TokenizerRegistry
Sourcepub fn generate_id() -> String
pub fn generate_id() -> String
Generate a new UUID for a tokenizer
Sourcepub async fn load<F, Fut>(
&self,
id: &str,
name: &str,
source: &str,
loader: F,
) -> Result<LoadOutcome, LoadError>
pub async fn load<F, Fut>( &self, id: &str, name: &str, source: &str, loader: F, ) -> Result<LoadOutcome, LoadError>
Load and register a tokenizer
Validates inputs, handles deduplication, and loads the tokenizer if needed. Per-key locking ensures only one load happens per name, preventing race conditions.
§Arguments
id- Pre-generated UUID (usegenerate_id()to create one)name- User-provided name (used for deduplication, must not be empty)source- Source path or HuggingFace model ID (must not be empty)loader- Async function that loads the tokenizer
§Returns
Ok(LoadOutcome::Loaded { id })- Tokenizer was newly loadedOk(LoadOutcome::AlreadyExists { id })- Tokenizer already existedErr(LoadError)- Validation failed or loading failed
Sourcepub fn get_by_id(&self, id: &str) -> Option<TokenizerEntry>
pub fn get_by_id(&self, id: &str) -> Option<TokenizerEntry>
Get a tokenizer by UUID
Sourcepub fn get_by_name(&self, name: &str) -> Option<TokenizerEntry>
pub fn get_by_name(&self, name: &str) -> Option<TokenizerEntry>
Get a tokenizer by name
Sourcepub fn get(&self, name_or_id: &str) -> Option<Arc<dyn Tokenizer>>
pub fn get(&self, name_or_id: &str) -> Option<Arc<dyn Tokenizer>>
Get a tokenizer (for backward compatibility, tries name first then ID)
Sourcepub fn contains_id(&self, id: &str) -> bool
pub fn contains_id(&self, id: &str) -> bool
Check if a tokenizer is registered by ID
Sourcepub fn list(&self) -> Vec<TokenizerEntry>
pub fn list(&self) -> Vec<TokenizerEntry>
List all registered tokenizers
Sourcepub fn remove_by_id(&self, id: &str) -> Option<TokenizerEntry>
pub fn remove_by_id(&self, id: &str) -> Option<TokenizerEntry>
Remove a tokenizer by ID
Returns the entry if it was present.
Sourcepub fn remove(&self, name: &str) -> Option<TokenizerEntry>
pub fn remove(&self, name: &str) -> Option<TokenizerEntry>
Remove a tokenizer by name
Returns the entry if it was present.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TokenizerRegistry
impl !RefUnwindSafe for TokenizerRegistry
impl Send for TokenizerRegistry
impl Sync for TokenizerRegistry
impl Unpin for TokenizerRegistry
impl UnsafeUnpin for TokenizerRegistry
impl !UnwindSafe for TokenizerRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more