Skip to content

Commit 5161b77

Browse files
committed
Replace Cow<'_, str> with String
In all three of nodeprep, nameprep and resourceprep, there was never a case where a Cow::Borrowed() was generated, so let’s simplify the API for everyone. This is a breaking change in the API.
1 parent bf7e494 commit 5161b77

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn is_prohibited_bidirectional_text(s: &str) -> bool {
122122
/// Nameprep is defined in [RFC 3491][].
123123
///
124124
/// [RFC 3491]: https://tools.ietf.org/html/rfc3491
125-
pub fn nameprep(s: &str) -> Result<Cow<'_, str>, Error> {
125+
pub fn nameprep(s: &str) -> Result<String, Error> {
126126
// 3. Mapping
127127
let mapped = s.chars()
128128
.filter(|&c| !tables::commonly_mapped_to_nothing(c))
@@ -162,15 +162,15 @@ pub fn nameprep(s: &str) -> Result<Cow<'_, str>, Error> {
162162
return Err(Error(ErrorCause::ProhibitedCharacter(c)));
163163
}
164164

165-
Ok(Cow::Owned(normalized))
165+
Ok(normalized)
166166
}
167167

168168
/// Prepares a string with the Nodeprep profile of the stringprep algorithm.
169169
///
170170
/// Nameprep is defined in [RFC 3920, Appendix A][].
171171
///
172172
/// [RFC 3920, Appendix A]: https://tools.ietf.org/html/rfc3920#appendix-A
173-
pub fn nodeprep(s: &str) -> Result<Cow<'_, str>, Error> {
173+
pub fn nodeprep(s: &str) -> Result<String, Error> {
174174
// A.3. Mapping
175175
let mapped = s.chars()
176176
.filter(|&c| !tables::commonly_mapped_to_nothing(c))
@@ -212,7 +212,7 @@ pub fn nodeprep(s: &str) -> Result<Cow<'_, str>, Error> {
212212
return Err(Error(ErrorCause::ProhibitedCharacter(c)));
213213
}
214214

215-
Ok(Cow::Owned(normalized))
215+
Ok(normalized)
216216
}
217217

218218
// Additional characters not allowed in JID nodes, by RFC3920.
@@ -228,7 +228,7 @@ fn prohibited_node_character(c: char) -> bool {
228228
/// Nameprep is defined in [RFC 3920, Appendix B][].
229229
///
230230
/// [RFC 3920, Appendix B]: https://tools.ietf.org/html/rfc3920#appendix-B
231-
pub fn resourceprep(s: &str) -> Result<Cow<'_, str>, Error> {
231+
pub fn resourceprep(s: &str) -> Result<String, Error> {
232232
// B.3. Mapping
233233
let mapped = s.chars()
234234
.filter(|&c| !tables::commonly_mapped_to_nothing(c))
@@ -268,7 +268,7 @@ pub fn resourceprep(s: &str) -> Result<Cow<'_, str>, Error> {
268268
return Err(Error(ErrorCause::ProhibitedCharacter(c)));
269269
}
270270

271-
Ok(Cow::Owned(normalized))
271+
Ok(normalized)
272272
}
273273

274274
#[cfg(test)]

0 commit comments

Comments
 (0)