http_protocol: add AnnounceEvent::as_str, run cargo fmt

This commit is contained in:
Joakim Frostegård 2022-04-02 13:31:51 +02:00
parent b9c029b5ed
commit 87223f7952
2 changed files with 18 additions and 3 deletions

View file

@ -52,6 +52,17 @@ impl FromStr for AnnounceEvent {
}
}
impl AnnounceEvent {
pub fn as_str(&self) -> Option<&str> {
match self {
Self::Started => Some("started"),
Self::Stopped => Some("stopped"),
Self::Completed => Some("completed"),
Self::Empty => None,
}
}
}
#[cfg(test)]
impl quickcheck::Arbitrary for InfoHash {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {

View file

@ -283,9 +283,13 @@ impl Request {
let query_string = split_parts.next().with_context(|| "no query string")?;
if location == "/announce" {
Ok(Request::Announce(AnnounceRequest::from_query_string(query_string)?))
Ok(Request::Announce(AnnounceRequest::from_query_string(
query_string,
)?))
} else {
Ok(Request::Scrape(ScrapeRequest::from_query_string(query_string)?))
Ok(Request::Scrape(ScrapeRequest::from_query_string(
query_string,
)?))
}
}