#[non_exhaustive]pub struct CreateAttachment {
pub filename: String,
pub description: Option<String>,
pub data: Vec<u8>,
/* private fields */
}
Expand description
A builder for creating a new attachment from a file path, file data, or URL.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.filename: String
§description: Option<String>
§data: Vec<u8>
Implementations§
Source§impl CreateAttachment
impl CreateAttachment
Sourcepub fn bytes(
data: impl Into<Vec<u8>>,
filename: impl Into<String>,
) -> CreateAttachment
pub fn bytes( data: impl Into<Vec<u8>>, filename: impl Into<String>, ) -> CreateAttachment
Builds an CreateAttachment
from the raw attachment data.
Sourcepub async fn file(
file: &File,
filename: impl Into<String>,
) -> Result<CreateAttachment>
pub async fn file( file: &File, filename: impl Into<String>, ) -> Result<CreateAttachment>
Builds an CreateAttachment
by reading from a file handler.
§Errors
Error::Io
error if reading the file fails.
Sourcepub async fn url(http: impl AsRef<Http>, url: &str) -> Result<CreateAttachment>
pub async fn url(http: impl AsRef<Http>, url: &str) -> Result<CreateAttachment>
Builds an CreateAttachment
by downloading attachment data from a URL.
§Errors
Error::Url
if the URL is invalid, Error::Http
if downloading the data fails.
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Converts the stored data to the base64 representation.
This is used in the library internally because Discord expects image data as base64 in many places.
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Sets a description for the file (max 1024 characters).
Trait Implementations§
Source§impl Clone for CreateAttachment
impl Clone for CreateAttachment
Source§fn clone(&self) -> CreateAttachment
fn clone(&self) -> CreateAttachment
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for CreateAttachment
impl Debug for CreateAttachment
Source§impl PartialEq for CreateAttachment
impl PartialEq for CreateAttachment
Source§impl Serialize for CreateAttachment
impl Serialize for CreateAttachment
impl StructuralPartialEq for CreateAttachment
Auto Trait Implementations§
impl Freeze for CreateAttachment
impl RefUnwindSafe for CreateAttachment
impl Send for CreateAttachment
impl Sync for CreateAttachment
impl Unpin for CreateAttachment
impl UnwindSafe for CreateAttachment
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