Skip to main content

GgufContext

Struct GgufContext 

Source
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

Source

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.

Source

pub fn n_kv(&self) -> i64

Returns the number of key-value pairs in the GGUF file.

Source

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.

Source

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.

Source

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()).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn n_tensors(&self) -> i64

Returns the number of tensors in the GGUF file.

Trait Implementations§

Source§

impl Drop for GgufContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more