Skip to content

Commit

Permalink
Use regular integer types for sizes/dimensions of images and videos (s…
Browse files Browse the repository at this point in the history
…erenity-rs#2472)

Signed-off-by: Miezhiko <[email protected]>
  • Loading branch information
Miezhiko authored Jun 27, 2023
1 parent 56867af commit 0c12aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/model/channel/attachment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::num::NonZeroU32;

#[cfg(feature = "model")]
use reqwest::Client as ReqwestClient;

Expand Down Expand Up @@ -41,15 +39,15 @@ pub struct Attachment {
/// Sescription for the file (max 1024 characters).
pub description: Option<String>,
/// If the attachment is an image, then the height of the image is provided.
pub height: Option<NonZeroU32>,
pub height: Option<u32>,
/// The proxy URL.
pub proxy_url: String,
/// The size of the file in bytes.
pub size: NonZeroU32,
pub size: u32,
/// The URL of the uploaded attachment.
pub url: String,
/// If the attachment is an image, then the width of the image is provided.
pub width: Option<NonZeroU32>,
pub width: Option<u32>,
/// The attachment's [media type].
///
/// [media type]: https://en.wikipedia.org/wiki/Media_type
Expand Down Expand Up @@ -82,7 +80,7 @@ impl Attachment {
/// If this attachment is an image, then a tuple of the width and height in pixels is returned.
#[must_use]
pub fn dimensions(&self) -> Option<(u32, u32)> {
self.width.and_then(|width| self.height.map(|height| (width.get(), height.get())))
self.width.and_then(|width| self.height.map(|height| (width, height)))
}

/// Downloads the attachment, returning back a vector of bytes.
Expand Down
14 changes: 6 additions & 8 deletions src/model/channel/embed.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::num::NonZeroU32;

use crate::model::{Colour, Timestamp};

/// Represents a rich embed which allows using richer markdown, multiple fields and more. This was
Expand Down Expand Up @@ -163,9 +161,9 @@ pub struct EmbedImage {
/// A proxied URL of the image.
pub proxy_url: Option<String>,
/// The height of the image.
pub height: Option<NonZeroU32>,
pub height: Option<u32>,
/// The width of the image.
pub width: Option<NonZeroU32>,
pub width: Option<u32>,
}

/// The provider of an embed.
Expand Down Expand Up @@ -193,9 +191,9 @@ pub struct EmbedThumbnail {
/// A proxied URL of the thumbnail.
pub proxy_url: Option<String>,
/// The height of the thumbnail in pixels.
pub height: Option<NonZeroU32>,
pub height: Option<u32>,
/// The width of the thumbnail in pixels.
pub width: Option<NonZeroU32>,
pub width: Option<u32>,
}

/// Video information for an embed.
Expand All @@ -209,7 +207,7 @@ pub struct EmbedVideo {
/// A proxied URL of the thumbnail.
pub proxy_url: Option<String>,
/// The height of the video in pixels.
pub height: Option<NonZeroU32>,
pub height: Option<u32>,
/// The width of the video in pixels.
pub width: Option<NonZeroU32>,
pub width: Option<u32>,
}

0 comments on commit 0c12aa8

Please sign in to comment.