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