|
1 | 1 | use crate::headers::{HeaderName, HeaderValue, Headers, ToHeaderValues, ETAG}; |
2 | 2 | use crate::{Error, StatusCode}; |
3 | 3 |
|
4 | | -use std::fmt::Debug; |
| 4 | +use std::fmt::{self, Debug, Display}; |
5 | 5 | use std::option; |
6 | 6 |
|
7 | 7 | /// HTTP Entity Tags. |
@@ -94,14 +94,6 @@ impl ETag { |
94 | 94 | matches!(self, Self::Weak(_)) |
95 | 95 | } |
96 | 96 |
|
97 | | - /// Convert an ETag to a String. |
98 | | - pub fn to_string(&self) -> String { |
99 | | - match self { |
100 | | - Self::Strong(s) => format!(r#""{}""#, s), |
101 | | - Self::Weak(s) => format!(r#"W/"{}""#, s), |
102 | | - } |
103 | | - } |
104 | | - |
105 | 97 | /// Create an Etag from a string. |
106 | 98 | pub(crate) fn from_str(s: &str) -> crate::Result<Self> { |
107 | 99 | let mut weak = false; |
@@ -138,6 +130,15 @@ impl ETag { |
138 | 130 | } |
139 | 131 | } |
140 | 132 |
|
| 133 | +impl Display for ETag { |
| 134 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 135 | + match self { |
| 136 | + Self::Strong(s) => write!(f, r#""{}""#, s), |
| 137 | + Self::Weak(s) => write!(f, r#"W/"{}""#, s), |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | + |
141 | 142 | impl ToHeaderValues for ETag { |
142 | 143 | type Iter = option::IntoIter<HeaderValue>; |
143 | 144 | fn to_header_values(&self) -> crate::Result<Self::Iter> { |
|
0 commit comments