Skip to content

Commit

Permalink
Add necessary lifetimes to do proper zero-copy
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Oct 25, 2021
1 parent 3814531 commit 2507e80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/events/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> Attribute<'a> {
/// This will allocate if the value contains any escape sequences.
///
/// See also [`unescaped_value_with_custom_entities()`](#method.unescaped_value_with_custom_entities)
pub fn unescaped_value(&self) -> Result<Cow<[u8]>> {
pub fn unescaped_value(&self) -> Result<Cow<'a, [u8]>> {
self.make_unescaped_value(None)
}

Expand All @@ -112,14 +112,14 @@ impl<'a> Attribute<'a> {
pub fn unescaped_value_with_custom_entities(
&self,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
) -> Result<Cow<[u8]>> {
) -> Result<Cow<'a, [u8]>> {
self.make_unescaped_value(Some(custom_entities))
}

fn make_unescaped_value(
&self,
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
) -> Result<Cow<[u8]>> {
) -> Result<Cow<'a, [u8]>> {
do_unescape(&self.value, custom_entities).map_err(Error::EscapeError)
}

Expand Down
28 changes: 14 additions & 14 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> BytesStart<'a> {
///
/// See also [`unescaped_with_custom_entities()`](#method.unescaped_with_custom_entities)
#[inline]
pub fn unescaped(&self) -> Result<Cow<[u8]>> {
pub fn unescaped(&self) -> Result<Cow<'a, [u8]>> {
self.make_unescaped(None)
}

Expand All @@ -207,18 +207,18 @@ impl<'a> BytesStart<'a> {
///
/// See also [`unescaped()`](#method.unescaped)
#[inline]
pub fn unescaped_with_custom_entities<'s>(
&'s self,
pub fn unescaped_with_custom_entities(
&self,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
) -> Result<Cow<'s, [u8]>> {
) -> Result<Cow<'a, [u8]>> {
self.make_unescaped(Some(custom_entities))
}

#[inline]
fn make_unescaped<'s>(
&'s self,
fn make_unescaped(
&self,
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
) -> Result<Cow<'s, [u8]>> {
) -> Result<Cow<'a, [u8]>> {
do_unescape(&self.buf, custom_entities).map_err(Error::EscapeError)
}

Expand Down Expand Up @@ -618,7 +618,7 @@ impl<'a> BytesText<'a> {
/// returns Malformed error with index within element if '&' is not followed by ';'
///
/// See also [`unescaped_with_custom_entities()`](#method.unescaped_with_custom_entities)
pub fn unescaped(&self) -> Result<Cow<[u8]>> {
pub fn unescaped(&self) -> Result<Cow<'a, [u8]>> {
self.make_unescaped(None)
}

Expand All @@ -633,17 +633,17 @@ impl<'a> BytesText<'a> {
/// The keys and values of `custom_entities`, if any, must be valid UTF-8.
///
/// See also [`unescaped()`](#method.unescaped)
pub fn unescaped_with_custom_entities<'s>(
&'s self,
pub fn unescaped_with_custom_entities(
&self,
custom_entities: &HashMap<Vec<u8>, Vec<u8>>,
) -> Result<Cow<'s, [u8]>> {
) -> Result<Cow<'a, [u8]>> {
self.make_unescaped(Some(custom_entities))
}

fn make_unescaped<'s>(
&'s self,
fn make_unescaped(
&self,
custom_entities: Option<&HashMap<Vec<u8>, Vec<u8>>>,
) -> Result<Cow<'s, [u8]>> {
) -> Result<Cow<'a, [u8]>> {
do_unescape(&self.content, custom_entities).map_err(Error::EscapeError)
}

Expand Down

0 comments on commit 2507e80

Please sign in to comment.