use crate::*;
#[macro_export]
macro_rules! paragraphs {
($(#[$attr:meta])* $name:ident $(#[$impl_attr:meta])* { $($par:expr)* }) => {
$(#[$attr])*
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct $name {
index: usize,
}
$(#[$impl_attr])*
impl $name {
pub fn new() -> Self {
$name {
index: 0,
}
}
#[allow(unused_assignments)]
#[allow(unused_variables)]
#[allow(unused_mut)]
#[allow(clippy::useless_format)]
pub fn text(&self) -> String {
let mut curr = 0;
$({
if curr == self.index {
return $par.to_string();
} else {
curr += 1;
}
})*
String::new()
}
#[allow(unused_mut)]
pub fn next(self) -> Control<Self> {
let mut max = 0;
$({
stringify!($par);
max += 1;
})*
if max > 0 && self.index < max - 1 {
next($name {
index: self.index + 1
})
} else {
exit()
}
}
}
};
}
paragraphs! {
#[doc = "An example struct generated by the [`paragraphs!`](macro.paragraphs.html) macro."]
#[doc = ""]
#[doc = "All structs generated by [`paragraphs!`](macro.paragraphs.html) will have the same functions."]
ParagraphsExample #[allow(dead_code)] {}
}
fn _compiles() {
paragraphs! {
Test {
"This is a test paragraph."
"The is paragraph number 2."
}
}
}