use crate::handler::BoxedHandler;
use crate::path_params::PathParams;
use http::Method;
pub enum RouteMatch<'a> {
Found {
handler: &'a BoxedHandler,
params: PathParams,
},
NotFound,
MethodNotAllowed {
allowed: Vec<Method>,
},
}
pub(crate) fn convert_path_params(path: &str) -> String {
let mut result = String::with_capacity(path.len());
for ch in path.chars() {
match ch {
'{' => {
result.push(':');
}
'}' => {
}
_ => {
result.push(ch);
}
}
}
result
}
pub(crate) fn normalize_path_for_comparison(path: &str) -> String {
let mut result = String::with_capacity(path.len());
let mut in_param = false;
for ch in path.chars() {
match ch {
':' => {
in_param = true;
result.push_str(":_");
}
'/' => {
in_param = false;
result.push('/');
}
_ if in_param => {
}
_ => {
result.push(ch);
}
}
}
result
}
pub(crate) fn normalize_prefix(prefix: &str) -> String {
if prefix.is_empty() {
return "/".to_string();
}
let segments: Vec<&str> = prefix.split('/').filter(|s| !s.is_empty()).collect();
if segments.is_empty() {
return "/".to_string();
}
let mut result = String::with_capacity(prefix.len() + 1);
for segment in segments {
result.push('/');
result.push_str(segment);
}
result
}