Skip to content

Commit

Permalink
Swap CreateAttachment::data to Bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Nov 6, 2024
1 parent 80c657e commit 6b8f613
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/builder/create_attachment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::Cow;
use std::path::Path;

use bytes::Bytes;
use serde::ser::{Serialize, SerializeSeq, Serializer};
use tokio::fs::File;
use tokio::io::AsyncReadExt;
Expand All @@ -21,15 +22,12 @@ use crate::model::id::AttachmentId;
pub struct CreateAttachment<'a> {
pub filename: Cow<'static, str>,
pub description: Option<Cow<'a, str>>,
pub data: Cow<'static, [u8]>,
pub data: Bytes,
}

impl<'a> CreateAttachment<'a> {
/// Builds an [`CreateAttachment`] from the raw attachment data.
pub fn bytes(
data: impl Into<Cow<'static, [u8]>>,
filename: impl Into<Cow<'static, str>>,
) -> Self {
pub fn bytes(data: impl Into<Bytes>, filename: impl Into<Cow<'static, str>>) -> Self {
CreateAttachment {
data: data.into(),
filename: filename.into(),
Expand Down Expand Up @@ -85,7 +83,7 @@ impl<'a> CreateAttachment<'a> {
filename: impl Into<Cow<'static, str>>,
) -> Result<Self> {
let response = http.client.get(url).send().await?;
let data = response.bytes().await?.to_vec();
let data = response.bytes().await?;

Ok(CreateAttachment::bytes(data, filename))
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::internal::prelude::*;

impl CreateAttachment<'_> {
fn into_part(self) -> Result<Part> {
let mut part = Part::bytes(self.data);
let mut part = Part::stream(self.data);
part = guess_mime_str(part, &self.filename)?;
part = part.file_name(self.filename);
Ok(part)
Expand Down

0 comments on commit 6b8f613

Please sign in to comment.