#[cfg(feature = "feat-base64")]
pub mod base64;
#[cfg(feature = "feat-hash")]
pub mod hash;
pub mod misc;
#[cfg(feature = "feat-random")]
pub mod random;
#[deprecated(
since = "0.8.0-rc.1",
note = "Use `string_v2` instead, v1 will be removed in 0.9.0."
)]
#[cfg(feature = "feat-string")]
pub mod string;
#[cfg(feature = "feat-string")]
pub mod string_v2;
#[macro_export]
macro_rules! now {
() => {{
match std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) {
Ok(t) => t,
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}
}};
}
#[macro_export]
macro_rules! init_tracing_simple {
() => {{
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
let fmt_layer = tracing_subscriber::fmt::layer().with_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into())
.from_env_lossy()
.add_directive("otel::tracing=trace".parse().unwrap())
.add_directive("h2=error".parse().unwrap())
.add_directive("tower=error".parse().unwrap())
.add_directive("hyper=error".parse().unwrap()),
);
tracing_subscriber::registry().with(fmt_layer).init();
}};
}
#[macro_export]
macro_rules! wrapper {
($(#[$outer:meta])* $vis:vis $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner:ty) $(, <$($plt_name:ident: $plt:lifetime),+>)? $(, derive($($derive:path),+))?) => {
$(#[$outer])*
$(#[derive($($derive),+)])?
#[repr(transparent)]
#[doc = concat!("\n\nThis is an auto-generated wrapper over `", stringify!($inner), "`")]
$vis struct $name$(<$($lt),+>)? {
$inner_vis inner: $inner,
$($(
$plt_name: std::marker::PhantomData<&$plt ()>,
),+)?
}
impl$(<$($lt),+>)? From<$inner> for $name$(<$($lt),+>)? {
#[inline]
fn from(inner: $inner) -> Self {
Self {
inner,
$($($plt_name: std::marker::PhantomData),+)?
}
}
}
impl$(<$($lt),+>)? std::borrow::Borrow<$inner> for $name$(<$($lt),+>)? {
fn borrow(&self) -> &$inner {
&self.inner
}
}
impl$(<$($lt),+>)? std::ops::Deref for $name$(<$($lt),+>)? {
type Target = $inner;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl$(<$($lt),+>)? std::ops::DerefMut for $name$(<$($lt),+>)? {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl$(<$($lt),+>)? AsRef<$inner> for $name$(<$($lt),+>)? {
fn as_ref(&self) -> &$inner {
&self.inner
}
}
impl$(<$($lt),+>)? $name$(<$($lt),+>)? {
#[inline]
#[doc = concat!("Creates a new instance of [`", stringify!($name), "`]")]
$vis const fn new(inner: $inner) -> Self {
Self {
inner,
$($($plt_name: std::marker::PhantomData),+)?
}
}
}
};
}
#[cfg(test)]
mod tests {
#![allow(unused)]
#![allow(unreachable_pub)]
wrapper!(pub MyString(String));
wrapper!(#[derive(Debug)] pub MyStringPub(pub String));
wrapper!(pub MyStringPubCrate(pub(crate) String));
wrapper!(pub MyStringDerived(String), derive(Debug, Clone, PartialEq, Eq, Hash));
wrapper!(pub MyStringPubInnerDerived(pub String), derive(Debug, Clone, PartialEq, Eq, Hash));
wrapper!(pub MyStringPubCrateInnerDerived(pub(crate) String), derive(Debug, Clone, PartialEq, Eq, Hash));
wrapper!(pub MyStringLifetime<'a>(&'a str));
wrapper!(pub MyStringLifetimePubInner<'a>(pub &'a str));
wrapper!(pub MyStringLifetimePubCrateInner<'a>(pub(crate) &'a str));
wrapper!(pub MyStringLifetimePubDerived<'a>(pub &'a str), derive(Debug, Clone, PartialEq, Eq, Hash));
wrapper!(pub MyStringLifetimePubMutDerived<'a>(pub &'a mut str), derive(Debug, PartialEq, Eq, Hash));
wrapper!(pub MyStringLifetimePubT<T>(pub T), derive(Debug, Clone));
wrapper!(pub MyStringLifetimePubRefT<'a, T>(pub &'a T), derive(Debug, Clone));
}
wrapper! {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub MyStringDerived(String)
}