File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
23
integration.
24
24
25
25
### Changed
26
+ - ` Token::from_encoded ` now accepts owned or borrowed strings (any type that
27
+ implements ` Into<Cow<'_, str>> ` ).
26
28
- Sealed the ` Diagnose ` trait.
27
29
- Implementation of the ` Default ` trait for ` Pointer ` now doesn't constrain the lifetime.
28
30
Original file line number Diff line number Diff line change @@ -74,9 +74,10 @@ impl<'a> Token<'a> {
74
74
/// ## Errors
75
75
/// Returns `InvalidEncodingError` if the input string is not a valid RFC
76
76
/// 6901 (`~` must be followed by `0` or `1`)
77
- pub fn from_encoded ( s : & ' a str ) -> Result < Self , EncodingError > {
77
+ pub fn from_encoded ( s : impl Into < Cow < ' a , str > > ) -> Result < Self , EncodingError > {
78
+ let inner = s. into ( ) ;
78
79
let mut escaped = false ;
79
- for ( offset, b) in s . bytes ( ) . enumerate ( ) {
80
+ for ( offset, b) in inner . bytes ( ) . enumerate ( ) {
80
81
match b {
81
82
b'/' => {
82
83
return Err ( EncodingError {
@@ -102,11 +103,11 @@ impl<'a> Token<'a> {
102
103
}
103
104
if escaped {
104
105
return Err ( EncodingError {
105
- offset : s . len ( ) ,
106
+ offset : inner . len ( ) ,
106
107
source : InvalidEncoding :: Tilde ,
107
108
} ) ;
108
109
}
109
- Ok ( Self { inner : s . into ( ) } )
110
+ Ok ( Self { inner } )
110
111
}
111
112
112
113
/// Constructs a `Token` from an arbitrary string.
You can’t perform that action at this time.
0 commit comments