Skip to content

Commit

Permalink
moved macro to its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
perpetualcacophony committed Jul 25, 2024
1 parent 3c9d52b commit c974569
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
28 changes: 2 additions & 26 deletions src/commands/eightball/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,8 @@ use rand::{
};
use std::fmt;

macro_rules! create_answer_consts {
(
affirmative {
$($text:literal $($weight:literal)?),+
}

non_committal {
$($text2:literal $($weight2:literal)?),+
}

negative {
$($text3:literal $($weight3:literal)?),+
}
) => {
macro_rules! weight {
($value:literal) => { $value };
() => { 1.0 }
}

pub const ANSWERS: Answers = Answers(&[
$(Answer { tone: AnswerTone::Affirmative, text: $text, weight: weight!($($weight)?)},)+
$(Answer { tone: AnswerTone::NonCommittal, text: $text2, weight: weight!($($weight2)?)} ,)+
$(Answer { tone: AnswerTone::Negative, text: $text3, weight: weight!($($weight3)?)} ,)+
]);
}
}
#[macro_use]
mod macros;

create_answer_consts! {
affirmative {
Expand Down
26 changes: 26 additions & 0 deletions src/commands/eightball/core/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
macro_rules! create_answer_consts {
(
affirmative {
$($text:literal $($weight:literal)?),+
}

non_committal {
$($text2:literal $($weight2:literal)?),+
}

negative {
$($text3:literal $($weight3:literal)?),+
}
) => {
macro_rules! weight {
($value:literal) => { $value };
() => { 1.0 }
}

pub const ANSWERS: Answers = Answers(&[
$(Answer { tone: AnswerTone::Affirmative, text: $text, weight: weight!($($weight)?)},)+
$(Answer { tone: AnswerTone::NonCommittal, text: $text2, weight: weight!($($weight2)?)} ,)+
$(Answer { tone: AnswerTone::Negative, text: $text3, weight: weight!($($weight3)?)} ,)+
]);
}
}

0 comments on commit c974569

Please sign in to comment.