parsers: clippy pass
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-12-15 20:15:35 +01:00
parent 2b433d7036
commit 9612367c77
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
13 changed files with 33 additions and 31 deletions

View file

@ -56,7 +56,7 @@ impl TryFrom<Element> for Conference {
extensions: Vec::new(),
};
for child in root.children().cloned() {
for child in root.children() {
if child.is("nick", ns::BOOKMARKS2) {
if conference.nick.is_some() {
return Err(Error::ParseError(

View file

@ -49,7 +49,7 @@ impl TryFrom<Element> for Caps {
let ver: String = get_attr!(elem, "ver", Required);
let hash = Hash {
algo: get_attr!(elem, "hash", Required),
hash: Base64.decode(&ver)?,
hash: Base64.decode(ver)?,
};
Ok(Caps {
ext: get_attr!(elem, "ext", Option),

View file

@ -177,8 +177,8 @@ impl From<DiscoInfoResult> for Element {
fn from(disco: DiscoInfoResult) -> Element {
Element::builder("query", ns::DISCO_INFO)
.attr("node", disco.node)
.append_all(disco.identities.into_iter())
.append_all(disco.features.into_iter())
.append_all(disco.identities)
.append_all(disco.features)
.append_all(disco.extensions.iter().cloned().map(Element::from))
.build()
}

View file

@ -48,7 +48,7 @@ impl TryFrom<Element> for Header {
check_no_children!(elem, "header");
check_no_unknown_attributes!(elem, "header", ["name"]);
let name: String = get_attr!(elem, "name", Required);
let text = String::from(elem.text());
let text = elem.text();
Ok(match name.to_lowercase().as_str() {
"authorization" => Header::Authorization(text),

View file

@ -291,7 +291,7 @@ impl From<Message> for Element {
);
body
}))
.append_all(message.payloads.into_iter())
.append_all(message.payloads)
.build()
}
}

View file

@ -5,6 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
/// The `http://jabber.org/protocol/muc` protocol.
#[allow(clippy::module_inception)]
pub mod muc;
/// The `http://jabber.org/protocol/muc#user` protocol.

View file

@ -271,6 +271,12 @@ generate_element!(
]
);
impl Default for MucUser {
fn default() -> Self {
Self::new()
}
}
impl MucUser {
/// Creates an empty MucUser
pub fn new() -> MucUser {

View file

@ -67,10 +67,11 @@ type Status = String;
type Priority = i8;
///
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Default, Clone, PartialEq)]
pub enum Type {
/// This value is not an acceptable 'type' attribute, it is only used
/// internally to signal the absence of 'type'.
#[default]
None,
/// An error has occurred regarding processing of a previously sent
@ -100,12 +101,6 @@ pub enum Type {
Unsubscribed,
}
impl Default for Type {
fn default() -> Type {
Type::None
}
}
impl FromStr for Type {
type Err = Error;
@ -350,7 +345,7 @@ impl From<Presence> for Element {
.attr("to", presence.to)
.attr("id", presence.id)
.attr("type", presence.type_)
.append_all(presence.show.into_iter())
.append_all(presence.show)
.append_all(presence.statuses.into_iter().map(|(lang, status)| {
Element::builder("status", ns::DEFAULT_NS)
.attr(
@ -370,7 +365,7 @@ impl From<Presence> for Element {
.append(format!("{}", presence.priority)),
)
})
.append_all(presence.payloads.into_iter())
.append_all(presence.payloads)
.build()
}
}

View file

@ -209,7 +209,7 @@ impl From<PubSubEvent> for Element {
PubSubEvent::PublishedItems { node, items } => {
Element::builder("items", ns::PUBSUB_EVENT)
.attr("node", node)
.append_all(items.into_iter())
.append_all(items)
}
PubSubEvent::RetractedItems { node, items } => {
Element::builder("items", ns::PUBSUB_EVENT)

View file

@ -11,6 +11,7 @@ pub mod event;
pub mod owner;
/// The `http://jabber.org/protocol/pubsub` protocol.
#[allow(clippy::module_inception)]
pub mod pubsub;
pub use self::event::PubSubEvent;

View file

@ -151,9 +151,9 @@ impl TryFrom<Element> for Action {
fn try_from(elem: Element) -> Result<Action, Error> {
match elem.name() {
"t" => Insert::try_from(elem).map(|insert| Action::Insert(insert)),
"e" => Erase::try_from(elem).map(|erase| Action::Erase(erase)),
"w" => Wait::try_from(elem).map(|wait| Action::Wait(wait)),
"t" => Insert::try_from(elem).map(Action::Insert),
"e" => Erase::try_from(elem).map(Action::Erase),
"w" => Wait::try_from(elem).map(Action::Wait),
_ => Err(Error::ParseError("This is not a rtt action element.")),
}
}

View file

@ -76,7 +76,7 @@ impl WhitespaceAwareBase64 {
.chars()
.filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t')
.collect();
Ok(Base64Engine.decode(&s)?)
Ok(Base64Engine.decode(s)?)
}
pub fn encode(b: &[u8]) -> Option<String> {

View file

@ -23,19 +23,18 @@ pub struct XhtmlIm {
impl XhtmlIm {
/// Serialise formatted text to HTML.
pub fn to_html(self) -> String {
pub fn into_html(self) -> String {
let mut html = Vec::new();
// TODO: use the best language instead.
for (lang, body) in self.bodies {
if let Some((lang, body)) = self.bodies.into_iter().next() {
if lang.is_empty() {
assert!(body.xml_lang.is_none());
} else {
assert_eq!(Some(lang), body.xml_lang);
}
for tag in body.children {
html.push(tag.to_html());
html.push(tag.into_html());
}
break;
}
html.concat()
}
@ -112,9 +111,9 @@ enum Child {
}
impl Child {
fn to_html(self) -> String {
fn into_html(self) -> String {
match self {
Child::Tag(tag) => tag.to_html(),
Child::Tag(tag) => tag.into_html(),
Child::Text(text) => text,
}
}
@ -227,7 +226,7 @@ enum Tag {
}
impl Tag {
fn to_html(self) -> String {
fn into_html(self) -> String {
match self {
Tag::A {
href,
@ -468,7 +467,7 @@ fn children_to_nodes(children: Vec<Child>) -> impl IntoIterator<Item = Node> {
fn children_to_html(children: Vec<Child>) -> String {
children
.into_iter()
.map(|child| child.to_html())
.map(|child| child.into_html())
.collect::<Vec<_>>()
.concat()
}
@ -592,7 +591,7 @@ mod tests {
.unwrap();
let parsed = XhtmlIm::try_from(elem).unwrap();
let parsed2 = parsed.clone();
let html = parsed.to_html();
let html = parsed.into_html();
assert_eq!(html, "Hello world!");
let elem = Element::from(parsed2);
@ -605,14 +604,14 @@ mod tests {
.parse()
.unwrap();
let xhtml_im = XhtmlIm::try_from(elem).unwrap();
let html = xhtml_im.to_html();
let html = xhtml_im.into_html();
assert_eq!(html, "<p>Hello world!</p>");
let elem: Element = "<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><p>Hello <strong>world</strong>!</p></body></html>"
.parse()
.unwrap();
let xhtml_im = XhtmlIm::try_from(elem).unwrap();
let html = xhtml_im.to_html();
let html = xhtml_im.into_html();
assert_eq!(html, "<p>Hello <strong>world</strong>!</p>");
}