Skip to content

Commit 3e70ce4

Browse files
Mingundralley
andcommitted
Improve documentation for constructors
Co-authored-by: Daniel Alley <[email protected]>
1 parent 2fbe977 commit 3e70ce4

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/events/mod.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ use attributes::{Attribute, Attributes};
5454
///
5555
/// In well-formed XML it could contain a Byte-Order-Mark (BOM). If this event
5656
/// contains something else except BOM, the XML should be considered ill-formed.
57+
///
58+
/// This is a reader-only event. If you need to write a text before the first tag,
59+
/// use the [`BytesText`] event.
5760
#[derive(Debug, Clone, Eq, PartialEq)]
5861
pub struct BytesStartText<'a> {
5962
content: BytesText<'a>,
@@ -142,7 +145,7 @@ impl<'a> BytesStart<'a> {
142145
///
143146
/// # Warning
144147
///
145-
/// `name` is not checked to be a valid name
148+
/// `name` must be a valid name.
146149
#[inline]
147150
pub fn new<C: Into<Cow<'a, str>>>(name: C) -> Self {
148151
let buf = str_cow_to_bytes(name);
@@ -156,7 +159,9 @@ impl<'a> BytesStart<'a> {
156159
///
157160
/// # Warning
158161
///
159-
/// `&content[..name_len]` is not checked to be a valid name
162+
/// `&content[..name_len]` must be a valid name, and the remainder of `content`
163+
/// must be correctly-formed attributes. Neither are checked, it is possible
164+
/// to generate invalid XML if `content` or `name_len` are incorrect.
160165
#[inline]
161166
pub fn from_content<C: Into<Cow<'a, str>>>(content: C, name_len: usize) -> Self {
162167
BytesStart {
@@ -236,7 +241,7 @@ impl<'a> BytesStart<'a> {
236241
///
237242
/// # Warning
238243
///
239-
/// `name` is not checked to be a valid name
244+
/// `name` must be a valid name.
240245
pub fn set_name(&mut self, name: &[u8]) -> &mut BytesStart<'a> {
241246
let bytes = self.buf.to_mut();
242247
bytes.splice(..self.name_len, name.iter().cloned());
@@ -604,7 +609,11 @@ impl<'a> BytesEnd<'a> {
604609
BytesEnd { name }
605610
}
606611

607-
/// Creates a new `BytesEnd` borrowing a slice
612+
/// Creates a new `BytesEnd` borrowing a slice.
613+
///
614+
/// # Warning
615+
///
616+
/// `name` must be a valid name.
608617
#[inline]
609618
pub fn new<C: Into<Cow<'a, str>>>(name: C) -> Self {
610619
Self::wrap(str_cow_to_bytes(name))
@@ -812,7 +821,11 @@ impl<'a> BytesCData<'a> {
812821
}
813822
}
814823

815-
/// Creates a new `BytesCData` from a string
824+
/// Creates a new `BytesCData` from a string.
825+
///
826+
/// # Warning
827+
///
828+
/// `content` must not contain the `]]>` sequence.
816829
#[inline]
817830
pub fn new<C: Into<Cow<'a, str>>>(content: C) -> Self {
818831
Self::wrap(str_cow_to_bytes(content), Decoder::utf8())

0 commit comments

Comments
 (0)