题目在这里
pub fn prefix_matches(prefix: &str, request_path: &str) -> bool {
//split by slash and change element into Option and add None at the end.
let mut prefixs = prefix.split("/").map(|p| Some(p)).chain(std::iter::once(None));
let mut request_paths = request_path.split("/").map(|p| Some(p)).chain(std::iter::once(None));
//matching every two element
for (prefix, path) in prefixs.zip(request_paths) {
match (prefix, path) {
(Some(prefix), Some(path)) => {
if prefix != "*" && prefix != path {
return false;
}
}
(Some(_), None) => return false,
(None, Some(_)) => break,
(None, None) => break,
}
}
true
}