Skip to content

Commit

Permalink
feat: just use &'a [u8]
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgotf committed Sep 22, 2022
1 parent 5d23287 commit cb5703f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions twilight-model/src/http/attachment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Models used when sending attachments to Discord.
use std::borrow::Cow;

use serde::{Deserialize, Serialize};

/// Attachments used in messages.
Expand All @@ -12,7 +10,6 @@ use serde::{Deserialize, Serialize};
/// description for screen readers:
///
/// ```
/// use std::borrow::Cow;
/// use twilight_model::http::attachment::Attachment;
///
/// let filename = "twilight_sparkle.json".to_owned();
Expand All @@ -35,7 +32,7 @@ pub struct Attachment<'a> {
pub description: Option<String>,
/// Content of the file.
#[serde(skip)]
pub file: Cow<'a, [u8]>,
pub file: &'a [u8],
/// Name of the file.
///
/// Examples may be "twilight_sparkle.png", "cat.jpg", or "logs.txt".
Expand All @@ -57,16 +54,15 @@ impl<'a> Attachment<'a> {
/// Create an attachment with a grocery list named "grocerylist.txt":
///
/// ```
/// use std::borrow::Cow;
/// use twilight_model::http::attachment::Attachment;
///
/// let filename = "grocerylist.txt".to_owned();
/// let file_content = b"Apples\nGrapes\nLemonade".to_vec();
/// let file_content = b"Apples\nGrapes\nLemonade";
/// let id = 1;
///
/// let attachment = Attachment::from_bytes(filename, Cow::from(file_content), id);
/// let attachment = Attachment::from_bytes(filename, &file_content, id);
/// ```
pub const fn from_bytes(filename: String, file: Cow<'a, [u8]>, id: u64) -> Self {
pub const fn from_bytes(filename: String, file: &'a [u8], id: u64) -> Self {
Self {
description: None,
file,
Expand Down

0 comments on commit cb5703f

Please sign in to comment.