1use percent_encoding::{AsciiSet, NON_ALPHANUMERIC, utf8_percent_encode};
2
3const SAFE_CHARS: &AsciiSet = &NON_ALPHANUMERIC
4 .remove(b'/')
5 .remove(b'-')
6 .remove(b'_')
7 .remove(b':')
8 .remove(b'.')
9 .remove(b'{')
10 .remove(b'}');
11
12pub fn encode_route(path: &str) -> String {
13 utf8_percent_encode(path, SAFE_CHARS).to_string()
14}
15
16pub fn decode_path(path: &str) -> String {
17 percent_encoding::percent_decode_str(path)
18 .decode_utf8_lossy()
19 .trim_start_matches('/')
20 .to_string()
21}