mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
xmpp-parsers: Fix most of the clippy warnings
Only the non-looping loop is kept for now, until we find a better solution.
This commit is contained in:
parent
b51d6cec3a
commit
69f480e709
8 changed files with 29 additions and 33 deletions
|
@ -156,11 +156,7 @@ impl Field {
|
||||||
// > treat a FORM_TYPE field without an explicit type attribute,
|
// > treat a FORM_TYPE field without an explicit type attribute,
|
||||||
// > in data forms of type "submit", as the FORM_TYPE field with
|
// > in data forms of type "submit", as the FORM_TYPE field with
|
||||||
// > the special meaning defined herein.
|
// > the special meaning defined herein.
|
||||||
DataFormType::Submit => match self.type_ {
|
DataFormType::Submit => matches!(self.type_, FieldType::Hidden | FieldType::TextSingle),
|
||||||
FieldType::Hidden => true,
|
|
||||||
FieldType::TextSingle => true,
|
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
|
|
||||||
// XEP-0068 does not explicitly mention cancel type forms.
|
// XEP-0068 does not explicitly mention cancel type forms.
|
||||||
// However, XEP-0004 states:
|
// However, XEP-0004 states:
|
||||||
|
|
|
@ -295,7 +295,7 @@ impl TryFrom<Element> for Method {
|
||||||
check_no_children!(elem, "regex");
|
check_no_children!(elem, "regex");
|
||||||
Method::Regex(elem.text())
|
Method::Regex(elem.text())
|
||||||
}
|
}
|
||||||
_ => return Err(Error::Other("Encountered invalid validation method.").into()),
|
_ => return Err(Error::Other("Encountered invalid validation method.")),
|
||||||
};
|
};
|
||||||
Ok(method)
|
Ok(method)
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,8 +163,8 @@ pub fn hash_ecaps2(data: &[u8], algo: Algo) -> Result<Hash, Error> {
|
||||||
hasher.finalize_variable(&mut vec).unwrap();
|
hasher.finalize_variable(&mut vec).unwrap();
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
Algo::Sha_1 => return Err(Error::Other("Disabled algorithm sha-1: unsafe.").into()),
|
Algo::Sha_1 => return Err(Error::Other("Disabled algorithm sha-1: unsafe.")),
|
||||||
Algo::Unknown(_algo) => return Err(Error::Other("Unknown algorithm in ecaps2.").into()),
|
Algo::Unknown(_algo) => return Err(Error::Other("Unknown algorithm in ecaps2.")),
|
||||||
},
|
},
|
||||||
algo,
|
algo,
|
||||||
})
|
})
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl FromStr for Show {
|
||||||
"dnd" => Show::Dnd,
|
"dnd" => Show::Dnd,
|
||||||
"xa" => Show::Xa,
|
"xa" => Show::Xa,
|
||||||
|
|
||||||
_ => return Err(Error::Other("Invalid value for show.").into()),
|
_ => return Err(Error::Other("Invalid value for show.")),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ type Status = String;
|
||||||
|
|
||||||
type Priority = i8;
|
type Priority = i8;
|
||||||
|
|
||||||
///
|
/// Accepted values for the 'type' attribute of a presence.
|
||||||
#[derive(Debug, Default, Clone, PartialEq)]
|
#[derive(Debug, Default, Clone, PartialEq)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
/// This value is not an acceptable 'type' attribute, it is only used
|
/// This value is not an acceptable 'type' attribute, it is only used
|
||||||
|
@ -114,7 +114,9 @@ impl FromStr for Type {
|
||||||
"unsubscribed" => Type::Unsubscribed,
|
"unsubscribed" => Type::Unsubscribed,
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
return Err(Error::Other("Invalid 'type' attribute on presence element.").into());
|
return Err(Error::Other(
|
||||||
|
"Invalid 'type' attribute on presence element.",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
|
||||||
None => is_retract = Some(false),
|
None => is_retract = Some(false),
|
||||||
Some(false) => (),
|
Some(false) => (),
|
||||||
Some(true) => {
|
Some(true) => {
|
||||||
return Err(Error::Other("Mix of item and retract in items element.").into());
|
return Err(Error::Other("Mix of item and retract in items element."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items.push(Item::try_from(child.clone())?);
|
items.push(Item::try_from(child.clone())?);
|
||||||
|
@ -106,7 +106,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
|
||||||
None => is_retract = Some(true),
|
None => is_retract = Some(true),
|
||||||
Some(true) => (),
|
Some(true) => (),
|
||||||
Some(false) => {
|
Some(false) => {
|
||||||
return Err(Error::Other("Mix of item and retract in items element.").into());
|
return Err(Error::Other("Mix of item and retract in items element."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_no_children!(child, "retract");
|
check_no_children!(child, "retract");
|
||||||
|
@ -114,7 +114,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
|
||||||
let id = get_attr!(child, "id", Required);
|
let id = get_attr!(child, "id", Required);
|
||||||
retracts.push(id);
|
retracts.push(id);
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::Other("Invalid child in items element.").into());
|
return Err(Error::Other("Invalid child in items element."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(match is_retract {
|
Ok(match is_retract {
|
||||||
|
@ -123,7 +123,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
|
||||||
node,
|
node,
|
||||||
items: retracts,
|
items: retracts,
|
||||||
},
|
},
|
||||||
None => return Err(Error::Other("Missing children in items element.").into()),
|
None => return Err(Error::Other("Missing children in items element.")),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,12 +242,12 @@ impl PubSubEvent {
|
||||||
/// Return the name of the node to which this event is related.
|
/// Return the name of the node to which this event is related.
|
||||||
pub fn node_name(&self) -> &NodeName {
|
pub fn node_name(&self) -> &NodeName {
|
||||||
match self {
|
match self {
|
||||||
Self::Purge { node, .. } => &node,
|
Self::Purge { node, .. } => node,
|
||||||
Self::PublishedItems { node, .. } => &node,
|
Self::PublishedItems { node, .. } => node,
|
||||||
Self::RetractedItems { node, .. } => &node,
|
Self::RetractedItems { node, .. } => node,
|
||||||
Self::Subscription { node, .. } => &node,
|
Self::Subscription { node, .. } => node,
|
||||||
Self::Delete { node, .. } => &node,
|
Self::Delete { node, .. } => node,
|
||||||
Self::Configuration { node, .. } => &node,
|
Self::Configuration { node, .. } => node,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ impl TryFrom<Element> for Rtt {
|
||||||
seq,
|
seq,
|
||||||
event,
|
event,
|
||||||
id,
|
id,
|
||||||
actions: actions,
|
actions,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,7 +291,7 @@ impl TryFrom<Element> for StanzaError {
|
||||||
if condition == DefinedCondition::Gone || condition == DefinedCondition::Redirect {
|
if condition == DefinedCondition::Gone || condition == DefinedCondition::Redirect {
|
||||||
stanza_error.alternate_address = child.nodes().find_map(|node| {
|
stanza_error.alternate_address = child.nodes().find_map(|node| {
|
||||||
let Node::Text(text) = node else { return None };
|
let Node::Text(text) = node else { return None };
|
||||||
return Some(text.to_string());
|
Some(text.to_string())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,9 @@ impl TryFrom<Element> for VCard {
|
||||||
fn try_from(value: Element) -> Result<Self, Self::Error> {
|
fn try_from(value: Element) -> Result<Self, Self::Error> {
|
||||||
// Check that the root element is <vCard>
|
// Check that the root element is <vCard>
|
||||||
if !value.is("vCard", ns::VCARD) {
|
if !value.is("vCard", ns::VCARD) {
|
||||||
return Err(Error::Other("Root element is not <vCard xmlns='vcard-temp'>").into());
|
return Err(Error::Other(
|
||||||
|
"Root element is not <vCard xmlns='vcard-temp'>",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the <PHOTO> element, if any.
|
// Parse the <PHOTO> element, if any.
|
||||||
|
@ -76,15 +78,11 @@ impl TryFrom<Element> for VCard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Element> for VCard {
|
impl From<VCard> for Element {
|
||||||
fn into(self) -> Element {
|
fn from(vcard: VCard) -> Element {
|
||||||
let mut builder = Element::builder("vCard", ns::VCARD);
|
Element::builder("vCard", ns::VCARD)
|
||||||
|
.append_all(vcard.photo)
|
||||||
if let Some(photo) = self.photo {
|
.build()
|
||||||
builder = builder.append(photo);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.build()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue