Make the announce info field optional

This commit is contained in:
Matt Joiner 2024-03-24 18:27:08 +11:00
parent 00c7f3150f
commit b184354c2f
No known key found for this signature in database
GPG key ID: 6B990B8185E7F782
3 changed files with 5 additions and 7 deletions

View file

@ -29,7 +29,8 @@ pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>(
/// A parsed .torrent file.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct TorrentMetaV1<BufType> {
pub announce: BufType,
#[serde(skip_serializing_if = "Option::is_none")]
pub announce: Option<BufType>,
#[serde(
rename = "announce-list",
default = "Vec::new",
@ -59,7 +60,7 @@ impl<BufType> TorrentMetaV1<BufType> {
if self.announce_list.iter().flatten().next().is_some() {
return itertools::Either::Left(self.announce_list.iter().flatten());
}
itertools::Either::Right(once(&self.announce))
itertools::Either::Right(self.announce.iter())
}
}