use std::collections::HashSet;
#[cfg(feature = "i18n")]
use unic_langid::LanguageIdentifier;
#[cfg(feature = "i18n")]
use unic_langid::LanguageIdentifierError;
#[cfg(feature = "rocket")]
mod rocket_impl;
#[cfg(feature = "axum")]
mod axum_impl;
#[cfg(feature = "actix-web")]
mod actix_web_impl;
#[cfg(feature = "warp")]
mod warp_impl;
#[cfg(not(feature = "i18n"))]
pub struct Page {
pub head_ids: HashSet<&'static str>,
pub head: String,
pub template: String,
}
#[cfg(feature = "i18n")]
pub struct Page {
pub head_ids: HashSet<&'static str>,
pub lang: LanguageIdentifier,
pub head: String,
pub template: String,
}
impl Page {
#[cfg(not(feature = "i18n"))]
#[allow(clippy::new_without_default)]
pub fn new() -> Page {
Page {
head_ids: HashSet::new(),
head: String::new(),
template: String::new(),
}
}
#[cfg(feature = "i18n")]
pub fn new(lang: LanguageIdentifier) -> Page {
Page {
head_ids: HashSet::new(),
lang,
head: String::new(),
template: String::new(),
}
}
pub fn add_elements_to_head(&mut self, id: &'static str, element: String) {
if self.head_ids.insert(id) {
self.head += &element;
}
}
}
#[cfg(feature = "i18n")]
pub struct Lang(pub LanguageIdentifier);
#[cfg(feature = "i18n")]
impl std::str::FromStr for Lang {
type Err = LanguageIdentifierError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse::<LanguageIdentifier>().map(Lang)
}
}
#[cfg(all(feature = "rocket", feature = "i18n"))]
impl<'a> ::rocket::request::FromParam<'a> for Lang {
type Error = LanguageIdentifierError;
fn from_param(param: &'a str) -> Result<Self, Self::Error> {
match LanguageIdentifier::from_bytes(param.as_bytes()) {
Ok(id) => Ok(Self(id)),
Err(error) => Err(error),
}
}
}