Skip to content

Commit 0a88fb7

Browse files
committed
chore: use str:from_utf8 instead of String::from_utf8_lossy
1 parent edb59a7 commit 0a88fb7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
extern crate alloc;
140140

141141
use alloc::{
142-
string::{String, ToString as _},
142+
string::{String, ToString},
143143
vec::Vec,
144144
};
145145
use core::{
@@ -223,7 +223,7 @@ impl<T> PathTree<T> {
223223
// opt!
224224
raws: ranges
225225
.into_iter()
226-
.map(|r| from_utf8(&bytes[r]).unwrap())
226+
.filter_map(|r| from_utf8(&bytes[r]).ok())
227227
.rev()
228228
.collect(),
229229
}
@@ -239,7 +239,7 @@ impl<T> PathTree<T> {
239239

240240
/// Generates URL with the params.
241241
pub fn url_for(&self, index: usize, params: &[&str]) -> Option<String> {
242-
self.get_route(index).map(|(_, pieces)| {
242+
self.get_route(index).and_then(|(_, pieces)| {
243243
let mut bytes = Vec::new();
244244
let mut iter = params.iter();
245245

@@ -254,7 +254,7 @@ impl<T> PathTree<T> {
254254
}
255255
});
256256

257-
String::from_utf8_lossy(&bytes).to_string()
257+
from_utf8(&bytes).map(ToString::to_string).ok()
258258
})
259259
}
260260
}
@@ -308,7 +308,7 @@ impl<'a, 'b, T> Path<'a, 'b, T> {
308308
},
309309
});
310310

311-
String::from_utf8_lossy(&bytes).to_string()
311+
from_utf8(&bytes).map(ToString::to_string).unwrap()
312312
}
313313

314314
/// Returns the parameters of the current path.

0 commit comments

Comments
 (0)