Skip to main content

MediaAttachment

Struct MediaAttachment 

pub struct MediaAttachment {
    pub file_name: String,
    pub data: Vec<u8>,
    pub mime_type: Option<String>,
    pub marker: Option<RenderedMarker>,
}
Expand description

A single media attachment on an inbound message.

Fields§

§file_name: String

Original file name (e.g. voice.ogg, photo.jpg).

§data: Vec<u8>

Raw bytes of the attachment.

§mime_type: Option<String>

MIME type if known (e.g. audio/ogg, image/jpeg).

§marker: Option<RenderedMarker>

The marker the receiving channel already rendered into the message text for these bytes, if it rendered one: the exact target it referenced and the disposition it chose.

This field creates the fact. A channel’s text rendering is otherwise unrecoverable from the envelope: file_name is the sender’s name, which need not equal the on-disk name the channel marked (Discord prefixes a UUID; a URL fallback is not a file name at all), and nothing else records whether the channel rendered an image or a document. Consumers that need to know whether the text already carries a re-loadable reference to this attachment, or which disposition the channel committed to, must read this rather than pattern-matching the rendered text, which also carries sender-authored content.

None means the channel supplied bytes without rendering a marker for them; consumers must then treat the attachment as unreferenced.

Implementations§

Source§

impl MediaAttachment

Source

pub fn from_file(path: &str) -> Result<Self>

Load an attachment from a file path on disk.

§Caller path-validation contract

This method reads the path supplied by the caller verbatim. Callers are responsible for validating or constraining path before calling this function when the path originates from untrusted input (e.g. a user message, an HTTP request body, or any external data source). No sandboxing or path canonicalization is performed here.

Read errors are propagated as Err rather than silently producing an empty attachment, so the caller can decide how to handle missing or unreadable files.

Source

pub fn marker_target(&self) -> Option<&str>

The exact target the receiving channel rendered for these bytes, if it rendered a marker. See RenderedMarker::target.

Source

pub fn channel_rendered_remote_image_target(&self) -> Option<&str>

Return the target of a channel-rendered image marker that points at a remote URL while the attachment bytes remain available in memory.

Such a marker is a fallback reference rather than an owned, reloadable image: the default provider path does not fetch remote images. A later media-enrichment stage can therefore remove this exact channel marker and replace it with the typed bytes without treating a sender-authored marker as channel metadata.

Source

pub fn channel_rendered_owned_disposition(&self) -> bool

Whether the receiving channel already rendered a marker whose disposition a later enrichment stage must not override.

See MarkerKind::defers_enrichment. The channel saw the payload, the sender’s declared type, and the transport’s own notion of what was sent, so its image-or-document verdict wins over a second, payload-only classification downstream. A remote URL image fallback is excluded: its typed bytes can replace the URL when remote fetching is disabled.

Source

pub fn kind(&self) -> MediaKind

Classify this attachment into a MediaKind.

Source

pub fn looks_like_image(&self) -> bool

Conservative image check for security-sensitive consumers.

kind() resolves each attachment to a single kind with MIME taking precedence, which is right for routing but wrong for a safety gate: MIME is sender-supplied, so a contradictory value (say video/mp4 on a real photo) or a missing extension would let an image slip past a kind() == Image check. This method instead treats the attachment as an image when ANY signal says so: an image/* MIME, an image file extension, or image magic bytes in the payload. A false positive only over-applies image-turn restrictions, which is the safe direction.

Source

pub fn provider_loadable_image_mime(&self) -> Option<&'static str>

The MIME the multimodal image loader will assign these bytes, if that MIME is one the provider path can actually send.

Where looks_like_image answers “must this turn be treated as carrying an image?” (deliberately permissive, because its consumers only ever remove capability), this answers the narrower question “will an [IMAGE:<path>] reference to these bytes survive provider preparation?” — so it is the signal for any decision that grants image handling: emitting an image marker, or routing a turn to a vision provider.

None means the loader would reject the reference and drop it in favour of a “could not be loaded” note. Callers must then keep the bytes reachable some other way rather than emitting a marker that is guaranteed to be discarded.

Trait Implementations§

Source§

impl Clone for MediaAttachment

Source§

fn clone(&self) -> MediaAttachment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · §

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MediaAttachment

Source§

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

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

impl Default for MediaAttachment

Source§

fn default() -> MediaAttachment

Returns the “default value” for a 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> 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.