Attachment

Enum Attachment 

Source
pub enum Attachment {
    Local(PathBuf),
    Remote(Url),
    InMemory {
        bytes: Vec<u8>,
        file_name: Option<String>,
        mime_type: Option<String>,
    },
}
Expand description

Represents a resource that can be attached to a payload or produced by an agent.

Attachments provide a flexible way to handle various types of data sources:

  • Local files on the filesystem
  • Remote resources accessible via URLs
  • In-memory data with optional metadata

Variants§

§

Local(PathBuf)

A file on the local filesystem.

§

Remote(Url)

A resource accessible via a URL (e.g., http://, https://, s3://).

Note: Remote fetching is not yet implemented. This variant is reserved for future functionality.

§

InMemory

In-memory data with optional name and MIME type.

Fields

§bytes: Vec<u8>

The raw bytes of the attachment.

§file_name: Option<String>

Optional file name for identification.

§mime_type: Option<String>

Optional MIME type (e.g., “image/png”, “application/pdf”).

Implementations§

Source§

impl Attachment

Source

pub fn local(path: impl Into<PathBuf>) -> Self

Creates a new local file attachment.

§Examples
use llm_toolkit::attachment::Attachment;
use std::path::PathBuf;

let attachment = Attachment::local(PathBuf::from("/path/to/file.png"));
Source

pub fn remote(url: &str) -> Self

Creates a new remote URL attachment.

§Panics

Panics if the URL string is invalid. For fallible construction, use Url::parse() and construct Attachment::Remote(url) directly.

§Examples
use llm_toolkit::attachment::Attachment;

let attachment = Attachment::remote("https://example.com/image.png");
Source

pub fn in_memory(bytes: Vec<u8>) -> Self

Creates a new in-memory attachment from raw bytes.

§Examples
use llm_toolkit::attachment::Attachment;

let data = vec![0x89, 0x50, 0x4E, 0x47]; // PNG header
let attachment = Attachment::in_memory(data);
Source

pub fn in_memory_with_meta( bytes: Vec<u8>, file_name: Option<String>, mime_type: Option<String>, ) -> Self

Creates a new in-memory attachment with metadata.

§Examples
use llm_toolkit::attachment::Attachment;

let data = vec![0x89, 0x50, 0x4E, 0x47];
let attachment = Attachment::in_memory_with_meta(
    data,
    Some("chart.png".to_string()),
    Some("image/png".to_string()),
);
Source

pub fn file_name(&self) -> Option<String>

Returns the file name if available.

For local files, extracts the file name from the path. For remote URLs, extracts the last path segment. For in-memory attachments, returns the stored file name.

§Examples
use llm_toolkit::attachment::Attachment;
use std::path::PathBuf;

let attachment = Attachment::local(PathBuf::from("/path/to/file.png"));
assert_eq!(attachment.file_name(), Some("file.png".to_string()));
Source

pub fn mime_type(&self) -> Option<String>

Returns the MIME type if available or can be inferred.

For local files, attempts to infer the MIME type from the file extension. For in-memory attachments, returns the stored MIME type. For remote URLs, returns None.

§Examples
use llm_toolkit::attachment::Attachment;
use std::path::PathBuf;

let attachment = Attachment::local(PathBuf::from("/path/to/file.png"));
assert_eq!(attachment.mime_type(), Some("image/png".to_string()));

Trait Implementations§

Source§

impl Clone for Attachment

Source§

fn clone(&self) -> Attachment

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Attachment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Attachment

Source§

fn eq(&self, other: &Attachment) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ToAttachments for Attachment

Source§

fn to_attachments(&self) -> Vec<(String, Attachment)>

Converts this type into a list of named attachments. Read more
Source§

impl Eq for Attachment

Source§

impl StructuralPartialEq for Attachment

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> ErasedDestructor for T
where T: 'static,