pub struct AddedTokenSet { /* private fields */ }Expand description
An owned content → AddedToken set: what a backend is handed to build its
matcher from.
A bare FxHashMap<String, u32> cannot express the strip flags, and every
caller that has none (GGUF, the bundled vocabularies, tests) still gets to
pass one — the From impls below turn it into a set of
plain tokens — so only the tokenizer.json loader
pays the cost of spelling the flags out.
Implementations§
Source§impl AddedTokenSet
impl AddedTokenSet
Sourcepub fn insert(&mut self, content: impl Into<String>, token: AddedToken)
pub fn insert(&mut self, content: impl Into<String>, token: AddedToken)
Declare content as an added token with explicit flags.
Sourcepub fn insert_plain(&mut self, content: impl Into<String>, id: u32)
pub fn insert_plain(&mut self, content: impl Into<String>, id: u32)
Declare content as an added token with both strip flags off.
Sourcepub fn get(&self, content: &str) -> Option<AddedToken>
pub fn get(&self, content: &str) -> Option<AddedToken>
The token declared for content, if any.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, AddedToken)> + '_
pub fn iter(&self) -> impl Iterator<Item = (&str, AddedToken)> + '_
Iterate the declared tokens as (content, token) pairs.
Sourcepub fn into_id_map(self) -> FxHashMap<String, u32>
pub fn into_id_map(self) -> FxHashMap<String, u32>
Consume the set into the plain name→id map the rest of the crate speaks
(decode tables, SpecialPolicy’s named lookups). Consuming rather than
borrowing moves the token strings instead of cloning every one of them.
Trait Implementations§
Source§impl Clone for AddedTokenSet
impl Clone for AddedTokenSet
Source§fn clone(&self) -> AddedTokenSet
fn clone(&self) -> AddedTokenSet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AddedTokenSet
impl Debug for AddedTokenSet
Source§impl Default for AddedTokenSet
impl Default for AddedTokenSet
Source§fn default() -> AddedTokenSet
fn default() -> AddedTokenSet
Source§impl From<&HashMap<String, u32, FxBuildHasher>> for AddedTokenSet
impl From<&HashMap<String, u32, FxBuildHasher>> for AddedTokenSet
Source§impl From<HashMap<String, u32, FxBuildHasher>> for AddedTokenSet
impl From<HashMap<String, u32, FxBuildHasher>> for AddedTokenSet
Source§impl FromIterator<(String, AddedToken)> for AddedTokenSet
impl FromIterator<(String, AddedToken)> for AddedTokenSet
Source§fn from_iter<T: IntoIterator<Item = (String, AddedToken)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (String, AddedToken)>>(iter: T) -> Self
Auto Trait Implementations§
impl Freeze for AddedTokenSet
impl RefUnwindSafe for AddedTokenSet
impl Send for AddedTokenSet
impl Sync for AddedTokenSet
impl Unpin for AddedTokenSet
impl UnsafeUnpin for AddedTokenSet
impl UnwindSafe for AddedTokenSet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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