diff --git a/CHANGELOG.md b/CHANGELOG.md index f586a8b..7c40983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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>`). - Sealed the `Diagnose` trait. - Implementation of the `Default` trait for `Pointer` now doesn't constrain the lifetime. diff --git a/src/token.rs b/src/token.rs index 25119c1..94298ba 100644 --- a/src/token.rs +++ b/src/token.rs @@ -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 { + pub fn from_encoded(s: impl Into>) -> Result { + 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 { @@ -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.