use lazy_static::lazy_static;
use cargo_manifest::{Manifest, Package};
use std::fs::read;
pub mod datetime;
pub mod encoder;
pub mod encoder_aes;
pub mod env;
pub mod file;
pub mod folder;
pub mod formatter;
pub mod id;
pub mod image;
pub mod json;
pub mod numbers;
pub mod random;
pub mod strings;
pub mod tls;
pub mod validatorr;
pub mod zone1970;
pub use chrono::Local;
pub use datetime::*;
pub use encoder::*;
pub use encoder_aes::*;
pub use env::*;
pub use file::*;
pub use folder::*;
pub use formatter::*;
pub use id::*;
pub use image::*;
pub use json::*;
pub use numbers::*;
pub use random::*;
pub use strings::*;
pub use tls::*;
use std::any::type_name;
pub fn type_of<T>(_: T) -> &'static str {
type_name::<T>()
}
lazy_static! {
pub static ref TEMP_DIR: String = std::env::temp_dir().as_path().display().to_string();
pub static ref ROOT_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
pub static ref MANIFEST: Manifest = Manifest::from_slice(&read("Cargo.toml").unwrap()).unwrap();
pub static ref PACKAGE: &'static Package = MANIFEST.package.as_ref().unwrap();
}
#[allow(dead_code)]
#[cfg(windows)]
pub const NEWLINE: &'static str = "\r\n";
#[allow(dead_code)]
#[cfg(not(windows))]
pub const NEWLINE: &str = "\n";
pub fn print_line(s: String) {
#[rustfmt::skip]
println!("{} STDOUT [{}:{}] - {}", date_string(), module_path!(), line!(), s);
}
pub fn print_error(s: String) {
#[rustfmt::skip]
println!("{} STDERR [{}:{}] - {}", date_string(), module_path!(), line!(), s);
}
pub fn log_once(line: String) {
if !crate::core::cacheable::exists60s(&line) {
log::info!("{}", line);
crate::core::cacheable::put60s(&line, "");
}
}
pub fn get_function_name<F, Args>(_: &F) -> &'static str
where
F: actix_web::Handler<Args>,
Args: actix_web::FromRequest + 'static,
F::Output: actix_web::Responder + 'static,
{
std::any::type_name::<F>()
}
pub fn service_home() -> String {
std::env::current_dir().unwrap().display().to_string()
}
pub fn error_chain_fmt(
e: &impl std::error::Error,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
writeln!(f, "{}\n", e)?;
let mut current = e.source();
while let Some(cause) = current {
writeln!(f, "Caused by:\n\t{}", cause)?;
current = cause.source();
}
Ok(())
}