Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
integration.

### Changed
- `Token::from_encoded` now accepts owned or borrowed strings (any type that
implements `Into<Cow<'_, str>>`).
- Sealed the `Diagnose` trait.
- Implementation of the `Default` trait for `Pointer` now doesn't constrain the lifetime.

Expand Down
9 changes: 5 additions & 4 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ impl<'a> Token<'a> {
/// ## Errors
/// Returns `InvalidEncodingError` if the input string is not a valid RFC
/// 6901 (`~` must be followed by `0` or `1`)
pub fn from_encoded(s: &'a str) -> Result<Self, EncodingError> {
pub fn from_encoded(s: impl Into<Cow<'a, str>>) -> Result<Self, EncodingError> {
let inner = s.into();
let mut escaped = false;
for (offset, b) in s.bytes().enumerate() {
for (offset, b) in inner.bytes().enumerate() {
match b {
b'/' => {
return Err(EncodingError {
Expand All @@ -102,11 +103,11 @@ impl<'a> Token<'a> {
}
if escaped {
return Err(EncodingError {
offset: s.len(),
offset: inner.len(),
source: InvalidEncoding::Tilde,
});
}
Ok(Self { inner: s.into() })
Ok(Self { inner })
}

/// Constructs a `Token` from an arbitrary string.
Expand Down
Loading