use axum::extract::Path as AxumPath;
use serde::Deserialize;
use uuid::Uuid;
pub type PathParams<T> = AxumPath<T>;
#[allow(dead_code)] pub trait PathExt {
fn id(&self) -> Result<i64, String>;
fn uuid(&self) -> Result<Uuid, String>;
}
impl<T: PathParamsExtract> PathExt for AxumPath<T> {
fn id(&self) -> Result<i64, String> {
Err("Use PathParams<i64> or a custom struct with Deserialize".to_string())
}
fn uuid(&self) -> Result<Uuid, String> {
Err("Use PathParams<Uuid> or a custom struct with Deserialize".to_string())
}
}
pub trait PathParamsExtract: for<'de> Deserialize<'de> {}
impl<T: for<'de> Deserialize<'de>> PathParamsExtract for T {}
#[allow(dead_code)] pub fn extract_id(path: &str) -> Result<i64, String> {
path.parse::<i64>()
.map_err(|_| format!("Invalid ID: {}", path))
}
#[allow(dead_code)] pub fn extract_uuid(path: &str) -> Result<Uuid, String> {
Uuid::parse_str(path)
.map_err(|_| format!("Invalid UUID: {}", path))
}