Make comments optional.
Add a default "comments" feature to transform comments into errors when unset. This is so that XMPP implementations don’t have to care about comments, as they can’t happen in the stream.
This commit is contained in:
parent
aa8018d999
commit
a91252c861
6 changed files with 32 additions and 1 deletions
|
|
@ -283,9 +283,14 @@ impl Element {
|
|||
Event::Eof => {
|
||||
return Err(Error::EndOfDocument);
|
||||
},
|
||||
#[cfg(not(feature = "comments"))]
|
||||
Event::Comment { .. } => {
|
||||
return Err(Error::CommentsDisabled);
|
||||
}
|
||||
#[cfg(feature = "comments")]
|
||||
Event::Comment { .. } => (),
|
||||
Event::Text { .. } |
|
||||
Event::End { .. } |
|
||||
Event::Comment { .. } |
|
||||
Event::CData { .. } |
|
||||
Event::Decl { .. } |
|
||||
Event::PI { .. } |
|
||||
|
|
@ -361,6 +366,9 @@ impl Element {
|
|||
Event::Eof => {
|
||||
break;
|
||||
},
|
||||
#[cfg(not(feature = "comments"))]
|
||||
Event::Comment(_) => return Err(Error::CommentsDisabled),
|
||||
#[cfg(feature = "comments")]
|
||||
Event::Comment(s) => {
|
||||
let comment = reader.decode(&s).into_owned();
|
||||
if comment != "" {
|
||||
|
|
@ -569,6 +577,7 @@ impl Element {
|
|||
///
|
||||
/// elem.append_comment_node("comment");
|
||||
/// ```
|
||||
#[cfg(feature = "comments")]
|
||||
pub fn append_comment_node<S: Into<String>>(&mut self, child: S) {
|
||||
self.children.push(Node::Comment(child.into()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue