diff --git a/bhttp/src/lib.rs b/bhttp/src/lib.rs index defad37..3c8fbde 100644 --- a/bhttp/src/lib.rs +++ b/bhttp/src/lib.rs @@ -66,15 +66,28 @@ impl TryFrom for StatusCode { type Error = Error; fn try_from(value: u64) -> Result { - let v = u16::try_from(value).map_err(|_| Error::InvalidStatus)?; - if matches!(v, 100..=599) { - Ok(Self(v)) + Self::try_from(u16::try_from(value).map_err(|_| Error::InvalidStatus)?) + } +} + +impl TryFrom for StatusCode { + type Error = Error; + + fn try_from(value: u16) -> Result { + if matches!(value, 100..=599) { + Ok(Self(value)) } else { Err(Error::InvalidStatus) } } } +impl From for u16 { + fn from(value: StatusCode) -> Self { + value.code() + } +} + pub trait ReadSeek: io::BufRead + io::Seek {} impl ReadSeek for io::Cursor where T: AsRef<[u8]> {} impl ReadSeek for io::BufReader where T: io::Read + io::Seek {}