pub struct File {
pub mime: MimeType,
pub source: FileSource,
pub meta: Value,
}Expand description
A blob of non-text content attached to or emitted by a message.
Mimetype is the single source of truth for what the bytes mean.
source is how to retrieve them. meta is a free-form bag for
provider-specific annotations — consumers that don’t care ignore it.
Fields§
§mime: MimeType§source: FileSource§meta: ValueImplementations§
Source§impl File
impl File
Sourcepub fn from_bytes(bytes: impl Into<Vec<u8>>) -> File
pub fn from_bytes(bytes: impl Into<Vec<u8>>) -> File
Construct a file from raw bytes, sniffing the mimetype from content.
Sourcepub fn from_bytes_with_mime(
bytes: impl Into<Vec<u8>>,
mime: impl Into<String>,
) -> File
pub fn from_bytes_with_mime( bytes: impl Into<Vec<u8>>, mime: impl Into<String>, ) -> File
Construct a file from raw bytes with an explicit mimetype.
pub fn from_path(path: impl AsRef<Path>) -> Result<File, Error>
Sourcepub fn from_url(
url: impl Into<String>,
mime: Option<&str>,
) -> Result<File, Box<dyn Error + Send + Sync>>
pub fn from_url( url: impl Into<String>, mime: Option<&str>, ) -> Result<File, Box<dyn Error + Send + Sync>>
Parse a URL. Mimetype defaults to application/octet-stream when
unknown — callers can supply a hint explicitly.
pub fn with_meta(self, meta: Value) -> File
pub fn is_image(&self) -> bool
pub fn is_audio(&self) -> bool
pub fn is_video(&self) -> bool
Sourcepub fn is_document(&self) -> bool
pub fn is_document(&self) -> bool
Anything that isn’t image/audio/video is treated as a document.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for File
impl<'de> Deserialize<'de> for File
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<File, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<File, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for File
impl Serialize for File
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for File
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
impl UnwindSafe for File
Blanket Implementations§
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
Mutably borrows from an owned value. Read more