parsers: clippy pass
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
2b433d7036
commit
9612367c77
13 changed files with 33 additions and 31 deletions
|
@ -56,7 +56,7 @@ impl TryFrom<Element> for Conference {
|
||||||
extensions: Vec::new(),
|
extensions: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for child in root.children().cloned() {
|
for child in root.children() {
|
||||||
if child.is("nick", ns::BOOKMARKS2) {
|
if child.is("nick", ns::BOOKMARKS2) {
|
||||||
if conference.nick.is_some() {
|
if conference.nick.is_some() {
|
||||||
return Err(Error::ParseError(
|
return Err(Error::ParseError(
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl TryFrom<Element> for Caps {
|
||||||
let ver: String = get_attr!(elem, "ver", Required);
|
let ver: String = get_attr!(elem, "ver", Required);
|
||||||
let hash = Hash {
|
let hash = Hash {
|
||||||
algo: get_attr!(elem, "hash", Required),
|
algo: get_attr!(elem, "hash", Required),
|
||||||
hash: Base64.decode(&ver)?,
|
hash: Base64.decode(ver)?,
|
||||||
};
|
};
|
||||||
Ok(Caps {
|
Ok(Caps {
|
||||||
ext: get_attr!(elem, "ext", Option),
|
ext: get_attr!(elem, "ext", Option),
|
||||||
|
|
|
@ -177,8 +177,8 @@ impl From<DiscoInfoResult> for Element {
|
||||||
fn from(disco: DiscoInfoResult) -> Element {
|
fn from(disco: DiscoInfoResult) -> Element {
|
||||||
Element::builder("query", ns::DISCO_INFO)
|
Element::builder("query", ns::DISCO_INFO)
|
||||||
.attr("node", disco.node)
|
.attr("node", disco.node)
|
||||||
.append_all(disco.identities.into_iter())
|
.append_all(disco.identities)
|
||||||
.append_all(disco.features.into_iter())
|
.append_all(disco.features)
|
||||||
.append_all(disco.extensions.iter().cloned().map(Element::from))
|
.append_all(disco.extensions.iter().cloned().map(Element::from))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl TryFrom<Element> for Header {
|
||||||
check_no_children!(elem, "header");
|
check_no_children!(elem, "header");
|
||||||
check_no_unknown_attributes!(elem, "header", ["name"]);
|
check_no_unknown_attributes!(elem, "header", ["name"]);
|
||||||
let name: String = get_attr!(elem, "name", Required);
|
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() {
|
Ok(match name.to_lowercase().as_str() {
|
||||||
"authorization" => Header::Authorization(text),
|
"authorization" => Header::Authorization(text),
|
||||||
|
|
|
@ -291,7 +291,7 @@ impl From<Message> for Element {
|
||||||
);
|
);
|
||||||
body
|
body
|
||||||
}))
|
}))
|
||||||
.append_all(message.payloads.into_iter())
|
.append_all(message.payloads)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
/// The `http://jabber.org/protocol/muc` protocol.
|
/// The `http://jabber.org/protocol/muc` protocol.
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
pub mod muc;
|
pub mod muc;
|
||||||
|
|
||||||
/// The `http://jabber.org/protocol/muc#user` protocol.
|
/// The `http://jabber.org/protocol/muc#user` protocol.
|
||||||
|
|
|
@ -271,6 +271,12 @@ generate_element!(
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
impl Default for MucUser {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MucUser {
|
impl MucUser {
|
||||||
/// Creates an empty MucUser
|
/// Creates an empty MucUser
|
||||||
pub fn new() -> MucUser {
|
pub fn new() -> MucUser {
|
||||||
|
|
|
@ -67,10 +67,11 @@ type Status = String;
|
||||||
type Priority = i8;
|
type Priority = i8;
|
||||||
|
|
||||||
///
|
///
|
||||||
#[derive(Debug, 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
|
||||||
/// internally to signal the absence of 'type'.
|
/// internally to signal the absence of 'type'.
|
||||||
|
#[default]
|
||||||
None,
|
None,
|
||||||
|
|
||||||
/// An error has occurred regarding processing of a previously sent
|
/// An error has occurred regarding processing of a previously sent
|
||||||
|
@ -100,12 +101,6 @@ pub enum Type {
|
||||||
Unsubscribed,
|
Unsubscribed,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Type {
|
|
||||||
fn default() -> Type {
|
|
||||||
Type::None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for Type {
|
impl FromStr for Type {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
|
@ -350,7 +345,7 @@ impl From<Presence> for Element {
|
||||||
.attr("to", presence.to)
|
.attr("to", presence.to)
|
||||||
.attr("id", presence.id)
|
.attr("id", presence.id)
|
||||||
.attr("type", presence.type_)
|
.attr("type", presence.type_)
|
||||||
.append_all(presence.show.into_iter())
|
.append_all(presence.show)
|
||||||
.append_all(presence.statuses.into_iter().map(|(lang, status)| {
|
.append_all(presence.statuses.into_iter().map(|(lang, status)| {
|
||||||
Element::builder("status", ns::DEFAULT_NS)
|
Element::builder("status", ns::DEFAULT_NS)
|
||||||
.attr(
|
.attr(
|
||||||
|
@ -370,7 +365,7 @@ impl From<Presence> for Element {
|
||||||
.append(format!("{}", presence.priority)),
|
.append(format!("{}", presence.priority)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.append_all(presence.payloads.into_iter())
|
.append_all(presence.payloads)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,7 +209,7 @@ impl From<PubSubEvent> for Element {
|
||||||
PubSubEvent::PublishedItems { node, items } => {
|
PubSubEvent::PublishedItems { node, items } => {
|
||||||
Element::builder("items", ns::PUBSUB_EVENT)
|
Element::builder("items", ns::PUBSUB_EVENT)
|
||||||
.attr("node", node)
|
.attr("node", node)
|
||||||
.append_all(items.into_iter())
|
.append_all(items)
|
||||||
}
|
}
|
||||||
PubSubEvent::RetractedItems { node, items } => {
|
PubSubEvent::RetractedItems { node, items } => {
|
||||||
Element::builder("items", ns::PUBSUB_EVENT)
|
Element::builder("items", ns::PUBSUB_EVENT)
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub mod event;
|
||||||
pub mod owner;
|
pub mod owner;
|
||||||
|
|
||||||
/// The `http://jabber.org/protocol/pubsub` protocol.
|
/// The `http://jabber.org/protocol/pubsub` protocol.
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
pub mod pubsub;
|
pub mod pubsub;
|
||||||
|
|
||||||
pub use self::event::PubSubEvent;
|
pub use self::event::PubSubEvent;
|
||||||
|
|
|
@ -151,9 +151,9 @@ impl TryFrom<Element> for Action {
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Action, Error> {
|
fn try_from(elem: Element) -> Result<Action, Error> {
|
||||||
match elem.name() {
|
match elem.name() {
|
||||||
"t" => Insert::try_from(elem).map(|insert| Action::Insert(insert)),
|
"t" => Insert::try_from(elem).map(Action::Insert),
|
||||||
"e" => Erase::try_from(elem).map(|erase| Action::Erase(erase)),
|
"e" => Erase::try_from(elem).map(Action::Erase),
|
||||||
"w" => Wait::try_from(elem).map(|wait| Action::Wait(wait)),
|
"w" => Wait::try_from(elem).map(Action::Wait),
|
||||||
_ => Err(Error::ParseError("This is not a rtt action element.")),
|
_ => Err(Error::ParseError("This is not a rtt action element.")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl WhitespaceAwareBase64 {
|
||||||
.chars()
|
.chars()
|
||||||
.filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t')
|
.filter(|ch| *ch != ' ' && *ch != '\n' && *ch != '\t')
|
||||||
.collect();
|
.collect();
|
||||||
Ok(Base64Engine.decode(&s)?)
|
Ok(Base64Engine.decode(s)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode(b: &[u8]) -> Option<String> {
|
pub fn encode(b: &[u8]) -> Option<String> {
|
||||||
|
|
|
@ -23,19 +23,18 @@ pub struct XhtmlIm {
|
||||||
|
|
||||||
impl XhtmlIm {
|
impl XhtmlIm {
|
||||||
/// Serialise formatted text to HTML.
|
/// Serialise formatted text to HTML.
|
||||||
pub fn to_html(self) -> String {
|
pub fn into_html(self) -> String {
|
||||||
let mut html = Vec::new();
|
let mut html = Vec::new();
|
||||||
// TODO: use the best language instead.
|
// 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() {
|
if lang.is_empty() {
|
||||||
assert!(body.xml_lang.is_none());
|
assert!(body.xml_lang.is_none());
|
||||||
} else {
|
} else {
|
||||||
assert_eq!(Some(lang), body.xml_lang);
|
assert_eq!(Some(lang), body.xml_lang);
|
||||||
}
|
}
|
||||||
for tag in body.children {
|
for tag in body.children {
|
||||||
html.push(tag.to_html());
|
html.push(tag.into_html());
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
html.concat()
|
html.concat()
|
||||||
}
|
}
|
||||||
|
@ -112,9 +111,9 @@ enum Child {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Child {
|
impl Child {
|
||||||
fn to_html(self) -> String {
|
fn into_html(self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Child::Tag(tag) => tag.to_html(),
|
Child::Tag(tag) => tag.into_html(),
|
||||||
Child::Text(text) => text,
|
Child::Text(text) => text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +226,7 @@ enum Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tag {
|
impl Tag {
|
||||||
fn to_html(self) -> String {
|
fn into_html(self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Tag::A {
|
Tag::A {
|
||||||
href,
|
href,
|
||||||
|
@ -468,7 +467,7 @@ fn children_to_nodes(children: Vec<Child>) -> impl IntoIterator<Item = Node> {
|
||||||
fn children_to_html(children: Vec<Child>) -> String {
|
fn children_to_html(children: Vec<Child>) -> String {
|
||||||
children
|
children
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|child| child.to_html())
|
.map(|child| child.into_html())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.concat()
|
.concat()
|
||||||
}
|
}
|
||||||
|
@ -592,7 +591,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let parsed = XhtmlIm::try_from(elem).unwrap();
|
let parsed = XhtmlIm::try_from(elem).unwrap();
|
||||||
let parsed2 = parsed.clone();
|
let parsed2 = parsed.clone();
|
||||||
let html = parsed.to_html();
|
let html = parsed.into_html();
|
||||||
assert_eq!(html, "Hello world!");
|
assert_eq!(html, "Hello world!");
|
||||||
|
|
||||||
let elem = Element::from(parsed2);
|
let elem = Element::from(parsed2);
|
||||||
|
@ -605,14 +604,14 @@ mod tests {
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let xhtml_im = XhtmlIm::try_from(elem).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>");
|
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>"
|
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()
|
.parse()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let xhtml_im = XhtmlIm::try_from(elem).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>");
|
assert_eq!(html, "<p>Hello <strong>world</strong>!</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue