btpeer 0.10.0

Simple CLI tool and library to get peers from TCP/HTTP and UDP BitTorrent trackers
Documentation
use std::str::FromStr;
use url::{ParseError, Url};

pub struct Scrape(Url);

impl Scrape {
    pub fn new(announce_url: &str, id20: &[[u8; 20]]) -> Result<Self, ParseError> {
        let mut url = Url::from_str(announce_url)?;

        url.set_path("scrape");

        url.set_query(Some(
            &id20
                .iter()
                .map(|hash| format!("info_hash={}", super::url_encode_bytes(hash)))
                .collect::<Vec<String>>()
                .join("&"),
        ));

        Ok(Self(url))
    }
}

impl std::fmt::Display for Scrape {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}