#[macro_export]
macro_rules! impl_getters {
($($(#[$attr:meta])* $visibility:vis $field:ident: $type:ty),*) => {
$(
$(#[$attr])*
$visibility fn $field(&self) -> &$type {
&self.$field
}
)*
};
($($(#[$attr:meta])* $visibility:vis const $field:ident: $type:ty),*) => {
$(
$(#[$attr])*
$visibility const fn $field(&self) -> &$type {
&self.$field
}
)*
};
}
#[macro_export]
macro_rules! impl_getters_mut {
($($visibility:vis $field:ident: $type:ty),*) => {
$(paste::paste!{
$visibility fn [<$field _mut>](&mut self) -> &mut $type {
&mut self.$field
}
})*
};
($($visibility:vis const $field:ident: $type:ty),*) => {
$(paste::paste!{
$visibility const fn [<$field _mut>](&mut self) -> &mut $type {
&mut self.$field
}
})*
};
}
#[macro_export]
macro_rules! impl_setters {
($($visibility:vis $field:ident: $type:ty),*) => {
$(paste::paste!{
$visibility fn [<set_ $field>](&mut self, val: $type) {
self.$field = val;
}
})*
};
($($visibility:vis const $field:ident: $type:ty),*) => {
$(paste::paste!{
$visibility const fn [<set_ $field>](&mut self, val: $type) {
self.$field = val;
}
})*
};
}
#[macro_export]
macro_rules! impl_new {
($(#[$attr:meta])* $visibility:vis $struct:ident$(< $($generic:ty),* >)?, $($arg:ident: $type:ty), *) => {
$(#[$attr])*
$visibility fn new($($arg: $type),*) -> $struct$(< $($generic),* >)? {
$struct {
$($arg), *
}
}
};
($(#[$attr:meta])* $visibility:vis const $struct:ident$(< $($generic:ty),* >)?, $($arg:ident: $type:ty), *) => {
$(#[$attr])*
$visibility const fn new($($arg: $type),*) -> $struct$(< $($generic),* >)? {
$struct {
$($arg), *
}
}
};
}
#[macro_export]
macro_rules! constraint {
{$x:expr} => {
[(); 0 - !$x as usize]
};
}
#[macro_export]
macro_rules! or {
($x:expr, $y:expr) => {
($x as u8 | $y as u8) == 1
};
}
#[macro_export]
macro_rules! and {
($x:expr, $y:expr) => {
($x as u8 & $y as u8) == 1
};
}
#[macro_export]
macro_rules! impl_from_mono_chrome_pixel_for_datacell {
($type:ty) => {
impl From<$type> for DataCell {
fn from(val: $type) -> Self {
Self {
character: val.character(),
foreground: TerminalColor::Default,
background: TerminalColor::Default,
}
}
}
};
}
#[macro_export]
macro_rules! impl_from_color_pixel_for_datacell {
($type:ty, $base:ty) => {
impl From<$type> for DataCell {
fn from(val: $type) -> Self {
let colors = val.pixels();
let grouping = TerminalColor::group(&colors);
let symb = <$base>::new(grouping).character();
let mut col1 = vec![];
let mut col2 = vec![];
for i in 0..grouping.len() {
if grouping[i] {
col1.push(colors[i]);
}
else {
col2.push(colors[i]);
}
}
let col1 = TerminalColor::mix(&col1);
let col2 = TerminalColor::mix(&col2);
Self {
character: symb,
foreground: col1,
background: col2,
}
}
}
};
}