xmpp-parsers: Make DiscoInfoResult::features a BTreeSet

Features must never be duplicated, so we can use a BTreeSet instead of a
Vec to be nicer for users.

It makes the internal API for computing caps and ecaps2 a bit worse,
because it was expecting a slice directly, so for now let’s collect the
BTreeSet into a Vec when computing the thing.  A refactor to use
Iterator might make it better eventually, but I won’t work on that
before profiling it.
This commit is contained in:
Link Mauve 2026-02-21 20:34:36 +01:00
commit bc88134c41
6 changed files with 20 additions and 9 deletions

View file

@ -16,6 +16,7 @@ use crate::{
},
tokio_xmpp::{Client as TokioXmppClient, connect::ServerConnector, xmlstream::Timeouts},
};
use std::collections::BTreeSet;
pub struct ClientBuilder<'a, C: ServerConnector> {
jid: BareJid,
@ -107,15 +108,16 @@ impl<C: ServerConnector> ClientBuilder<'_, C> {
"en",
self.config.disco.1.to_string(),
)];
let mut features = vec![String::from(ns::DISCO_INFO)];
let mut features = BTreeSet::new();
features.insert(String::from(ns::DISCO_INFO));
#[cfg(feature = "avatars")]
{
if self.features.contains(&ClientFeature::Avatars) {
features.push(format!("{}+notify", ns::AVATAR_METADATA));
features.insert(format!("{}+notify", ns::AVATAR_METADATA));
}
}
if self.features.contains(&ClientFeature::JoinRooms) {
features.push(format!("{}+notify", ns::BOOKMARKS2));
features.insert(format!("{}+notify", ns::BOOKMARKS2));
}
DiscoInfoResult {
node: None,