use core::ops::Deref;
#[derive(Copy, Clone, Eq, Debug)]
pub enum StrRef<'a> {
Static(&'static str),
Scratch(&'a str),
}
impl<'a> StrRef<'a> {
#[inline(always)]
pub const fn as_str(&self) -> &'a str {
match *self {
StrRef::Static(s) => s,
StrRef::Scratch(s) => s,
}
}
}
impl<'a> PartialEq for StrRef<'a> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_str() == other.as_str()
}
}
impl<'a> Deref for StrRef<'a> {
type Target = str;
#[inline]
fn deref(&self) -> &Self::Target {
self.as_str()
}
}
impl<'a> core::fmt::Display for StrRef<'a> {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
impl<'a> From<&'a str> for StrRef<'a> {
#[inline(always)]
fn from(s: &'a str) -> Self {
StrRef::Scratch(s)
}
}
#[macro_export]
macro_rules! fmt {
($cx:expr, $($arg:tt)*) => {
$cx.arena().alloc_fmt(core::format_args!($($arg)*))
};
}