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.
Implementations§
Source§impl Attachment
impl Attachment
Sourcepub fn local(path: impl Into<PathBuf>) -> Self
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"));Sourcepub fn in_memory(bytes: Vec<u8>) -> Self
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);Sourcepub fn in_memory_with_meta(
bytes: Vec<u8>,
file_name: Option<String>,
mime_type: Option<String>,
) -> Self
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()),
);Sourcepub fn file_name(&self) -> Option<String>
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()));Sourcepub fn mime_type(&self) -> Option<String>
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
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more