diff --git a/crates/ruma-common/src/events/image.rs b/crates/ruma-common/src/events/image.rs index c615cdb5..2d01d7d8 100644 --- a/crates/ruma-common/src/events/image.rs +++ b/crates/ruma-common/src/events/image.rs @@ -76,24 +76,49 @@ impl ImageEventContent { } } -/// Information about a thumbnail file content. -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +/// Image content. +#[derive(Default, Clone, Debug, Serialize, Deserialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ThumbnailFileContentInfo { - /// The mimetype of the thumbnail, e.g. `image/png`. +pub struct ImageContent { + /// The height of the image in pixels. #[serde(skip_serializing_if = "Option::is_none")] - pub mimetype: Option, + pub height: Option, - /// The size of the thumbnail in bytes. + /// The width of the image in pixels. #[serde(skip_serializing_if = "Option::is_none")] - pub size: Option, + pub width: Option, } -impl ThumbnailFileContentInfo { - /// Creates an empty `ThumbnailFileContentInfo`. +impl ImageContent { + /// Creates a new empty `ImageContent`. pub fn new() -> Self { Self::default() } + + /// Creates a new `ImageContent` with the given width and height. + pub fn with_size(width: UInt, height: UInt) -> Self { + Self { height: Some(height), width: Some(width) } + } +} + +/// Thumbnail content. +#[derive(Clone, Debug, Deserialize, Serialize)] +#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +pub struct ThumbnailContent { + /// The file info of the thumbnail. + #[serde(flatten)] + pub file: ThumbnailFileContent, + + /// The image info of the thumbnail. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub image: Option>, +} + +impl ThumbnailContent { + /// Creates a `ThumbnailContent` with the given file and image info. + pub fn new(file: ThumbnailFileContent, image: Option>) -> Self { + Self { file, image } + } } /// Thumbnail file content. @@ -136,47 +161,22 @@ impl ThumbnailFileContent { } } -/// Thumbnail content. -#[derive(Clone, Debug, Deserialize, Serialize)] +/// Information about a thumbnail file content. +#[derive(Clone, Debug, Default, Serialize, Deserialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ThumbnailContent { - /// The file info of the thumbnail. - #[serde(flatten)] - pub file: ThumbnailFileContent, - - /// The image info of the thumbnail. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub image: Option>, -} - -impl ThumbnailContent { - /// Creates a `ThumbnailContent` with the given file and image info. - pub fn new(file: ThumbnailFileContent, image: Option>) -> Self { - Self { file, image } - } -} - -/// Image content. -#[derive(Default, Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ImageContent { - /// The height of the image in pixels. +pub struct ThumbnailFileContentInfo { + /// The mimetype of the thumbnail, e.g. `image/png`. #[serde(skip_serializing_if = "Option::is_none")] - pub height: Option, + pub mimetype: Option, - /// The width of the image in pixels. + /// The size of the thumbnail in bytes. #[serde(skip_serializing_if = "Option::is_none")] - pub width: Option, + pub size: Option, } -impl ImageContent { - /// Creates a new empty `ImageContent`. +impl ThumbnailFileContentInfo { + /// Creates an empty `ThumbnailFileContentInfo`. pub fn new() -> Self { Self::default() } - - /// Creates a new `ImageContent` with the given width and height. - pub fn with_size(width: UInt, height: UInt) -> Self { - Self { height: Some(height), width: Some(width) } - } }