Skip to main content

llama_cpp_bindings/
token.rs

1use std::fmt::Debug;
2use std::fmt::Display;
3
4pub mod data;
5pub mod data_array;
6pub mod logit_bias;
7
8#[repr(transparent)]
9#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
10pub struct LlamaToken(pub llama_cpp_bindings_sys::llama_token);
11
12impl Display for LlamaToken {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        write!(f, "{}", self.0)
15    }
16}
17
18impl LlamaToken {
19    #[must_use]
20    pub const fn new(token_id: i32) -> Self {
21        Self(token_id)
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::LlamaToken;
28
29    #[test]
30    fn display_shows_inner_value() {
31        let token = LlamaToken::new(42);
32        assert_eq!(format!("{token}"), "42");
33    }
34}