use super::*;
impl FetchMethod {
pub fn as_str(&self) -> &'static str {
match self {
FetchMethod::Get => METHOD_GET,
FetchMethod::Post => METHOD_POST,
FetchMethod::Put => METHOD_PUT,
FetchMethod::Delete => METHOD_DELETE,
}
}
}
impl FetchResponse {
pub fn status(&self) -> u16 {
self.get_status()
}
pub fn is_ok(&self) -> bool {
(STATUS_OK_LOW..=STATUS_OK_HIGH).contains(&self.get_status())
}
pub fn bytes(&self) -> Vec<u8> {
self.get_body().clone()
}
pub fn text(&self) -> Option<String> {
from_utf8(&self.get_body().clone()).ok().map(str::to_string)
}
}
impl fmt::Display for FetchError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
match self {
FetchError::Transport(message) => write!(formatter, "transport: {message}"),
FetchError::Body(message) => write!(formatter, "body: {message}"),
}
}
}