rusty_s3/
method.rs

1use std::fmt::{self, Display};
2
3/// The HTTP request method for an [`S3Action`](crate::actions::S3Action).
4#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5pub enum Method {
6    Head,
7    Get,
8    Post,
9    Put,
10    Delete,
11}
12
13impl Method {
14    /// Convert this `Method` into an uppercase string.
15    ///
16    /// ```rust
17    /// # use rusty_s3::Method;
18    /// assert_eq!(Method::Get.to_str(), "GET");
19    /// ```
20    #[inline]
21    #[must_use]
22    pub const fn to_str(self) -> &'static str {
23        match self {
24            Self::Head => "HEAD",
25            Self::Get => "GET",
26            Self::Post => "POST",
27            Self::Put => "PUT",
28            Self::Delete => "DELETE",
29        }
30    }
31}
32
33impl Display for Method {
34    #[inline]
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        f.write_str(self.to_str())
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn to_str() {
46        assert_eq!(Method::Head.to_str(), "HEAD");
47        assert_eq!(Method::Get.to_str(), "GET");
48        assert_eq!(Method::Post.to_str(), "POST");
49        assert_eq!(Method::Put.to_str(), "PUT");
50        assert_eq!(Method::Delete.to_str(), "DELETE");
51    }
52
53    #[test]
54    fn display() {
55        assert_eq!(Method::Head.to_string(), "HEAD");
56        assert_eq!(Method::Get.to_string(), "GET");
57        assert_eq!(Method::Post.to_string(), "POST");
58        assert_eq!(Method::Put.to_string(), "PUT");
59        assert_eq!(Method::Delete.to_string(), "DELETE");
60    }
61}