pub struct GgufContext { /* private fields */ }Expand description
A safe wrapper around gguf_context.
Opens a GGUF file in metadata-only mode (no_alloc = true), allowing
inspection of key-value pairs and tensor metadata without loading tensor data.
Implementations§
Source§impl GgufContext
impl GgufContext
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, GgufContextError>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, GgufContextError>
Open a GGUF file and parse its metadata header.
§Errors
Returns GgufContextError::InitFailed if the file cannot be opened or parsed.
Returns GgufContextError::PathToStrError if the path is not valid UTF-8.
Returns GgufContextError::NulError if the path contains a null byte.
Sourcepub fn find_key(&self, key: &str) -> Result<i64, GgufContextError>
pub fn find_key(&self, key: &str) -> Result<i64, GgufContextError>
Find the index of a key by name.
§Errors
Returns GgufContextError::KeyNotFound if the key does not exist.
Returns GgufContextError::NulError if the key contains a null byte.
Sourcepub fn key_at(&self, key_id: i64) -> Result<&str, GgufContextError>
pub fn key_at(&self, key_id: i64) -> Result<&str, GgufContextError>
Returns the key name at the given index.
§Safety considerations
The caller must ensure key_id is in range [0, n_kv()).
§Errors
Returns GgufContextError::Utf8Error if the key name is not valid UTF-8.
Sourcepub fn kv_type(&self, key_id: i64) -> Option<GgufType>
pub fn kv_type(&self, key_id: i64) -> Option<GgufType>
Returns the value type of the key-value pair at the given index.
§Safety considerations
The caller must ensure key_id is in range [0, n_kv()).
Sourcepub fn val_u32(&self, key_id: i64) -> u32
pub fn val_u32(&self, key_id: i64) -> u32
Returns the u32 value at the given key index.
§Safety considerations
The caller must ensure the key at key_id has type GgufType::Uint32.
Sourcepub fn val_i32(&self, key_id: i64) -> i32
pub fn val_i32(&self, key_id: i64) -> i32
Returns the i32 value at the given key index.
§Safety considerations
The caller must ensure the key at key_id has type GgufType::Int32.
Sourcepub fn val_u64(&self, key_id: i64) -> u64
pub fn val_u64(&self, key_id: i64) -> u64
Returns the u64 value at the given key index.
§Safety considerations
The caller must ensure the key at key_id has type GgufType::Uint64.
Sourcepub fn val_str(&self, key_id: i64) -> Result<&str, GgufContextError>
pub fn val_str(&self, key_id: i64) -> Result<&str, GgufContextError>
Returns the string value at the given key index.
§Safety considerations
The caller must ensure the key at key_id has type GgufType::String.
§Errors
Returns GgufContextError::Utf8Error if the string value is not valid UTF-8.