use crate::path::PathWithoutLocale;
use crate::template::{Entity, EntityMap};
use sycamore::web::Html;
#[derive(Clone, Debug)]
pub struct FullRouteInfo<'a, G: Html> {
pub path: PathWithoutLocale,
pub entity: &'a Entity<G>,
pub was_incremental_match: bool,
pub locale: String,
}
#[derive(Clone, Debug)]
pub enum FullRouteVerdict<'a, G: Html> {
Found(FullRouteInfo<'a, G>),
NotFound {
locale: String,
},
LocaleDetection(PathWithoutLocale),
}
#[derive(Clone, Debug)]
pub struct RouteInfo {
pub path: PathWithoutLocale,
pub entity_name: String,
pub was_incremental_match: bool,
pub locale: String,
}
impl RouteInfo {
pub(crate) fn into_full<G: Html>(self, entities: &EntityMap<G>) -> FullRouteInfo<G> {
let entity = entities.get(&self.entity_name).expect("conversion to full route info failed, given entities did not contain given entity name");
FullRouteInfo {
path: self.path,
entity,
was_incremental_match: self.was_incremental_match,
locale: self.locale,
}
}
}
#[derive(Clone, Debug)]
pub enum RouteVerdict {
Found(RouteInfo),
NotFound {
locale: String,
},
LocaleDetection(PathWithoutLocale),
}
impl RouteVerdict {
pub(crate) fn into_full<G: Html>(self, entities: &EntityMap<G>) -> FullRouteVerdict<G> {
match self {
Self::Found(info) => FullRouteVerdict::Found(info.into_full(entities)),
Self::NotFound { locale } => FullRouteVerdict::NotFound { locale },
Self::LocaleDetection(dest) => FullRouteVerdict::LocaleDetection(dest),
}
}
}