Skip to content

Commit

Permalink
Re-add removed methods and add deprecations
Browse files Browse the repository at this point in the history
- Ease transition between versions
  • Loading branch information
bluk committed Nov 11, 2023
1 parent d437cea commit 6ef4d51
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
64 changes: 64 additions & 0 deletions maybe_xml/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ impl<'a> Token<'a> {
self.0
}

/// The token represented as a str.
///
/// # Errors
///
/// If the bytes are not a UTF-8 string.
#[deprecated(since = "0.8.0", note = "Use as_str() instead.")]
#[inline]
pub fn to_str(&self) -> Result<&'a str, core::str::Utf8Error> {
Ok(self.as_str())
}

/// The token represented as a str.
///
/// # Safety
///
/// The underlying bytes are assumed to be UTF-8. If the bytes are
/// not valid UTF-8, then the behavior is undefined.
#[deprecated(since = "0.8.0", note = "Use as_str() instead.")]
#[inline]
#[must_use]
pub const unsafe fn as_str_unchecked(&self) -> &'a str {
self.as_str()
}

/// Returns the underlying slice.
#[deprecated(since = "0.8.0", note = "Use as_bytes() instead.")]
#[inline]
#[must_use]
pub const fn into_inner(self) -> &'a [u8] {
self.as_bytes()
}

/// Returns the token type.
#[inline]
#[must_use]
Expand Down Expand Up @@ -139,6 +171,38 @@ macro_rules! converters {
pub const fn as_str(&self) -> &'a str {
self.0
}

/// The token represented as a str.
///
/// # Errors
///
/// If the bytes are not a UTF-8 string.
#[deprecated(since = "0.8.0", note = "Use as_str() instead.")]
#[inline]
pub fn to_str(&self) -> Result<&'a str, core::str::Utf8Error> {
Ok(self.as_str())
}

/// The token represented as a str.
///
/// # Safety
///
/// The underlying bytes are assumed to be UTF-8. If the bytes are
/// not valid UTF-8, then the behavior is undefined.
#[deprecated(since = "0.8.0", note = "Use as_str() instead.")]
#[inline]
#[must_use]
pub const unsafe fn as_str_unchecked(&self) -> &'a str {
self.as_str()
}

/// Returns the underlying slice.
#[deprecated(since = "0.8.0", note = "Use as_bytes() instead.")]
#[inline]
#[must_use]
pub const fn into_inner(self) -> &'a [u8] {
self.as_bytes()
}
}

impl<'a> From<&'a str> for $name<'a> {
Expand Down
32 changes: 32 additions & 0 deletions maybe_xml/src/token/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ macro_rules! converters {
pub const fn as_str(&self) -> &'a str {
self.0
}

/// The token property represented as a str.
///
/// # Errors
///
/// If the bytes are not a UTF-8 string.
#[deprecated(since = "0.8.0", note = "Use as_str() instead.")]
#[inline]
pub fn to_str(&self) -> Result<&'a str, str::Utf8Error> {
Ok(self.as_str())
}

/// The token property represented as a str.
///
/// # Safety
///
/// The underlying bytes are assumed to be UTF-8. If the bytes are
/// not valid UTF-8, then the behavior is undefined.
#[deprecated(since = "0.8.0", note = "Use as_str() instead.")]
#[inline]
#[must_use]
pub const unsafe fn as_str_unchecked(&self) -> &'a str {
self.as_str()
}

/// Returns the underlying slice.
#[deprecated(since = "0.8.0", note = "Use as_bytes() instead.")]
#[inline]
#[must_use]
pub const fn into_inner(self) -> &'a [u8] {
self.as_bytes()
}
}

impl<'a> From<&'a str> for $name<'a> {
Expand Down

0 comments on commit 6ef4d51

Please sign in to comment.