Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Move imports up
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Mar 20, 2022
1 parent fd04e5f commit a1ad40d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/events/mod.rs
Expand Up @@ -41,6 +41,7 @@ use encoding_rs::Encoding;
use std::{borrow::Cow, collections::HashMap, io::BufRead, ops::Deref, str::from_utf8};

use crate::escape::{do_unescape, escape};
use crate::utils::write_cow_string;
use crate::{errors::Error, errors::Result, reader::Reader};
use attributes::{Attribute, Attributes};

Expand Down Expand Up @@ -365,8 +366,6 @@ impl<'a> BytesStart<'a> {

impl<'a> std::fmt::Debug for BytesStart<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use crate::utils::write_cow_string;

write!(f, "BytesStart {{ buf: ")?;
write_cow_string(f, &self.buf)?;
write!(f, ", name_len: {} }}", self.name_len)
Expand Down Expand Up @@ -548,15 +547,14 @@ impl<'a> BytesEnd<'a> {

impl<'a> std::fmt::Debug for BytesEnd<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use crate::utils::write_cow_string;

write!(f, "BytesEnd {{ name: ")?;
write_cow_string(f, &self.name)?;
write!(f, " }}")
}
}

/// Data from various events (most notably, `Event::Text`).
/// Data from various events (most notably, `Event::Text`) that stored in XML
/// in escaped form. Internally data is stored in escaped form
#[derive(Clone, Eq, PartialEq)]
pub struct BytesText<'a> {
// Invariant: The content is always escaped.
Expand All @@ -566,24 +564,24 @@ pub struct BytesText<'a> {
impl<'a> BytesText<'a> {
/// Creates a new `BytesText` from an escaped byte sequence.
#[inline]
pub fn from_escaped<C: Into<Cow<'a, [u8]>>>(content: C) -> BytesText<'a> {
BytesText {
pub fn from_escaped<C: Into<Cow<'a, [u8]>>>(content: C) -> Self {
Self {
content: content.into(),
}
}

/// Creates a new `BytesText` from a byte sequence. The byte sequence is
/// expected not to be escaped.
#[inline]
pub fn from_plain(content: &'a [u8]) -> BytesText<'a> {
BytesText {
pub fn from_plain(content: &'a [u8]) -> Self {
Self {
content: escape(content),
}
}

/// Creates a new `BytesText` from an escaped string.
#[inline]
pub fn from_escaped_str<C: Into<Cow<'a, str>>>(content: C) -> BytesText<'a> {
pub fn from_escaped_str<C: Into<Cow<'a, str>>>(content: C) -> Self {
Self::from_escaped(match content.into() {
Cow::Owned(o) => Cow::Owned(o.into_bytes()),
Cow::Borrowed(b) => Cow::Borrowed(b.as_bytes()),
Expand All @@ -593,7 +591,7 @@ impl<'a> BytesText<'a> {
/// Creates a new `BytesText` from a string. The string is expected not to
/// be escaped.
#[inline]
pub fn from_plain_str(content: &'a str) -> BytesText<'a> {
pub fn from_plain_str(content: &'a str) -> Self {
Self::from_plain(content.as_bytes())
}

Expand Down Expand Up @@ -856,8 +854,6 @@ impl<'a> BytesText<'a> {

impl<'a> std::fmt::Debug for BytesText<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use crate::utils::write_cow_string;

write!(f, "BytesText {{ content: ")?;
write_cow_string(f, &self.content)?;
write!(f, " }}")
Expand Down

0 comments on commit a1ad40d

Please sign in to comment.