ImageData

Struct ImageData 

Source
pub struct ImageData {
    pub media_type: String,
    pub data: Vec<u8>,
}
Expand description

Helper structure for handling image data in prompts.

This struct provides a convenient way to represent images that can be included in multimodal prompts.

Fields§

§media_type: String

The MIME media type (e.g., “image/jpeg”, “image/png”).

§data: Vec<u8>

The raw image data.

Implementations§

Source§

impl ImageData

Source

pub fn new(media_type: impl Into<String>, data: Vec<u8>) -> Self

Creates a new ImageData instance with the given media type and data.

Source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self>

Creates an ImageData instance from a file path.

The media type is inferred from the file extension.

§Errors

Returns an error if the file cannot be read or if the media type cannot be determined from the file extension.

Source

pub fn from_base64( base64_str: &str, media_type: impl Into<String>, ) -> Result<Self, DecodeError>

Creates an ImageData instance from a base64-encoded string.

§Arguments
  • base64_str - The base64-encoded image data
  • media_type - The MIME media type of the image
§Errors

Returns an error if the base64 string cannot be decoded.

Source

pub fn to_base64(&self) -> String

Converts the image data to a base64-encoded string.

Trait Implementations§

Source§

impl Clone for ImageData

Source§

fn clone(&self) -> ImageData

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 ImageData

Source§

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

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

impl<'de> Deserialize<'de> for ImageData

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ImageData

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToPrompt for ImageData

Source§

fn to_prompt_parts(&self) -> Vec<PromptPart>

Converts the object into a vector of PromptParts using the default “full” mode. Read more
Source§

fn to_prompt_parts_with_mode(&self, mode: &str) -> Vec<PromptPart>

Converts the object into a vector of PromptParts based on a mode. Read more
Source§

fn to_prompt_with_mode(&self, mode: &str) -> String

Converts the object into a prompt string based on a mode. Read more
Source§

fn to_prompt(&self) -> String

Converts the object into a prompt string using the default “full” mode. Read more
Source§

fn prompt_schema() -> String

Returns a schema-level prompt for the type itself. Read more
Source§

impl TryFrom<&str> for ImageData

Source§

type Error = String

The type returned in the event of a conversion error.
Source§

fn try_from(data_url: &str) -> Result<Self, Self::Error>

Performs the conversion.

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,