ruma_common/media.rs
1//! Common types and functions for the [content repository].
2//!
3//! [content repository]: https://spec.matrix.org/latest/client-server-api/#content-repository
4
5use std::time::Duration;
6
7use crate::{serde::StringEnum, PrivOwnedStr};
8
9/// The desired resizing method for a thumbnail.
10#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
11#[derive(Clone, StringEnum)]
12#[ruma_enum(rename_all = "snake_case")]
13#[non_exhaustive]
14pub enum Method {
15 /// Crop the original to produce the requested image dimensions.
16 Crop,
17
18 /// Maintain the original aspect ratio of the source image.
19 Scale,
20
21 #[doc(hidden)]
22 _Custom(PrivOwnedStr),
23}
24
25/// The default duration that the client should be willing to wait to start receiving data.
26pub fn default_download_timeout() -> Duration {
27 Duration::from_secs(20)
28}
29
30/// Whether the given duration is the default duration that the client should be willing to wait to
31/// start receiving data.
32pub fn is_default_download_timeout(timeout: &Duration) -> bool {
33 timeout.as_secs() == 20
34}