use std::any::Any; use std::ops::Range; struct Message { source: String } trait Command { fn uppercase_name(&self) -> &str; fn from_message(msg: &Message) -> Self; fn to_message(&self) -> Message; } macro_rules! command { ($name: ident = $upper: expr { $($field: ident),* from_message: $param: ident -> $from: block to_message: $to: block }) => ( pub struct $name { pub source: String, $($field: Range),* } impl $name { $(pub fn $field(&self) -> &str { &self.source[self.$field.start as usize..self.$field.end as usize] })* } impl Command for $name { fn uppercase_name(&self) -> &str { $upper } fn from_message($param: &Message) -> $name { $from } fn to_message(&self) -> Message { $to } } ) } command! { PrivMsg = "PRIVMSG" { to, content } } fn main() {}