56 lines
952 B
Rust
56 lines
952 B
Rust
use {
|
|
std::{
|
|
collections::HashMap,
|
|
any::type_name,
|
|
time::{
|
|
SystemTime,
|
|
UNIX_EPOCH,
|
|
},
|
|
},
|
|
urlencoding::decode as url_decode,
|
|
uuid::Uuid,
|
|
crate::{
|
|
html::*,
|
|
},
|
|
};
|
|
|
|
|
|
#[allow(dead_code)]
|
|
pub fn type_of<T>(_: T) -> &'static str {
|
|
type_name::<T>()
|
|
}
|
|
|
|
pub fn uuid_v4() -> Uuid {
|
|
Uuid::new_v4()
|
|
}
|
|
|
|
pub fn build_html(body: &str) -> String {
|
|
format!("{}{}{}{}", HEADER_HTML, CSS3, body, FOOTER_HTML)
|
|
}
|
|
|
|
pub fn double_split(body: String, first: &str, second: &str) -> HashMap<String, String> {
|
|
body.split(first)
|
|
.filter_map(|c| {
|
|
c.split_once(second)
|
|
.map(|(l, r)| (
|
|
l.trim().to_owned(),
|
|
format!("{}", url_decode(r).expect("UTF-8")).trim().to_owned()
|
|
))
|
|
})
|
|
.collect::<HashMap<String, String>>()
|
|
}
|
|
|
|
pub fn time() -> u32 {
|
|
SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_secs() as u32
|
|
}
|
|
|
|
pub fn time_mcs() -> u128 {
|
|
SystemTime::now()
|
|
.duration_since(UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_micros()
|
|
}
|