pub use super::conf::*;
use axum::extract::{Multipart, Path, Query};
use phf::Map;
pub use rumtk_core::strings::RUMString;
pub use rumtk_core::strings::{AsStr, CompactStringExt, RUMStringConversions, StringLike};
use rumtk_core::types::{RUMHashMap, RUMID};
use std::fmt::{Debug, Display};
use std::sync::Arc;
pub type RUMWebData = RUMHashMap<RUMString, RUMString>;
pub type URLPath<'a, 'b> = &'a [&'b str];
pub type AsyncURLPath = Arc<Vec<RUMString>>;
pub type URLParams<'a> = &'a RUMWebData;
pub type AsyncURLParams = Arc<RUMWebData>;
pub use crate::utils::response::*;
pub type RenderedPageComponents = Vec<RUMString>;
pub type RenderedPageComponentsResult = RUMResult<RenderedPageComponents>;
pub type RouterComponents = Path<Vec<RUMString>>;
pub type RouterParams = Query<RUMWebData>;
pub type RouterForm = Multipart;
pub type ComponentFunction = fn(URLPath, URLParams, SharedAppState) -> HTMLResult;
pub type PageFunction = fn(SharedAppState) -> RenderedPageComponentsResult;
pub type ComponentMap = Map<&'static str, ComponentFunction>;
pub type PageMap = Map<&'static str, PageFunction>;
pub use crate::utils::form_data::{FormBuffer, FormData};
pub type RouterAPIPath = Path<RUMString>;
pub type APIPath = RUMString;
pub type APIFunction = fn(APIPath, RUMWebData, FormData, SharedAppState) -> HTMLResult;
pub use askama::Template as RUMWebTemplate;
use rumtk_core::core::RUMResult;
pub struct RUMWebDataProxy(RUMWebData);
impl RUMWebDataProxy {
pub fn get_inner(&self) -> &RUMWebData {
&self.0
}
pub fn from_params<K, V, const N: usize>(data: &[(K, V); N]) -> Self
where
K: Display + Sized,
V: Display + Sized,
{
let mut new_params = RUMWebData::with_capacity(data.len());
for (k, v) in data.iter() {
new_params.insert(
RUMString::from(k.to_string()),
RUMString::from(v.to_string()),
);
}
RUMWebDataProxy(new_params)
}
}
impl From<&RUMWebData> for RUMWebDataProxy {
fn from(data: &RUMWebData) -> Self {
RUMWebDataProxy(data.clone())
}
}
impl<const N: usize> From<&&[(&str, &str); N]> for RUMWebDataProxy {
fn from(data: &&[(&str, &str); N]) -> Self {
Self::from_params(data)
}
}
impl<const N: usize> From<&[(&str, &str); N]> for RUMWebDataProxy {
fn from(data: &[(&str, &str); N]) -> Self {
Self::from_params(data)
}
}
impl<const N: usize> From<&[(&str, &RUMString); N]> for RUMWebDataProxy {
fn from(data: &[(&str, &RUMString); N]) -> Self {
Self::from_params(data)
}
}
impl<const N: usize> From<&[(&str, RUMID); N]> for RUMWebDataProxy {
fn from(data: &[(&str, RUMID); N]) -> Self {
Self::from_params(data)
}
}