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: StringOriginal 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
impl MediaAttachment
Sourcepub fn from_file(path: &str) -> Result<MediaAttachment, Error>
pub fn from_file(path: &str) -> Result<MediaAttachment, Error>
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.
Sourcepub fn marker_target(&self) -> Option<&str>
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.
Sourcepub fn channel_rendered_remote_image_target(&self) -> Option<&str>
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.
Sourcepub fn channel_rendered_owned_disposition(&self) -> bool
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.
Sourcepub fn looks_like_image(&self) -> bool
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.
Sourcepub fn provider_loadable_image_mime(&self) -> Option<&'static str>
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
impl Clone for MediaAttachment
Source§fn clone(&self) -> MediaAttachment
fn clone(&self) -> MediaAttachment
1.0.0 (const: unstable) · §fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MediaAttachment
impl Debug for MediaAttachment
Source§impl Default for MediaAttachment
impl Default for MediaAttachment
Source§fn default() -> MediaAttachment
fn default() -> MediaAttachment
Auto Trait Implementations§
impl Freeze for MediaAttachment
impl RefUnwindSafe for MediaAttachment
impl Send for MediaAttachment
impl Sync for MediaAttachment
impl Unpin for MediaAttachment
impl UnsafeUnpin for MediaAttachment
impl UnwindSafe for MediaAttachment
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more