use core::fmt::{Display, Formatter};
macro_rules! unreachable_unchecked{
($reason:expr) => {
if cfg!(debug_assertions){
$crate::std::unreachable!($reason);
}else{
unsafe{$crate::std::hint::unreachable_unchecked()};
}
};
}
pub(crate) trait RefMut<T> {
fn ref_mut(&mut self) -> Option<&mut T>;
}
impl<'t, T> RefMut<T> for Option<&'t mut T> {
#[inline]
fn ref_mut(&mut self) -> Option<&mut T> {
self.as_mut().map(|x| &mut **x)
}
}
pub fn format_list<'lt, T: Display>(vec: &'lt [T], seperator: &'lt str) -> VecFormatter<'lt, T> {
VecFormatter(vec, seperator, " or ")
}
pub struct VecFormatter<'lt, T: Display>(pub &'lt [T], pub &'lt str, pub &'lt str);
impl<'lt, T: Display> Display for VecFormatter<'lt, T> {
#[inline]
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self.0 {
[] => f.write_str(" "),
[x] => {
f.write_str(self.1)?;
x.fmt(f)?;
f.write_str(self.1)
}
[ref body @ .., second_last, last] => {
for x in body {
f.write_str(self.1)?;
x.fmt(f)?;
f.write_str(self.1)?;
f.write_str(", ")?;
}
f.write_str(self.1)?;
second_last.fmt(f)?;
f.write_str(self.1)?;
f.write_str(self.2)?;
f.write_str(self.1)?;
last.fmt(f)?;
f.write_str(self.1)
}
}
}
}