diff options
Diffstat (limited to 'src/teamspeak/bbcode.rs')
| -rw-r--r-- | src/teamspeak/bbcode.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/teamspeak/bbcode.rs b/src/teamspeak/bbcode.rs new file mode 100644 index 0000000..28be08a --- /dev/null +++ b/src/teamspeak/bbcode.rs @@ -0,0 +1,42 @@ +use std::fmt::{Formatter, Display, Error}; + +#[allow(dead_code)] +pub enum BbCode<'a> { + Bold(&'a dyn Display), + Italic(&'a dyn Display), + Underline(&'a dyn Display), + Link(&'a dyn Display, &'a str), +} + +impl<'a> Display for BbCode<'a> { + fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { + match self { + BbCode::Bold(text) => fmt.write_fmt(format_args!("[B]{}[/B]", text))?, + BbCode::Italic(text) => fmt.write_fmt(format_args!("[I]{}[/I]", text))?, + BbCode::Underline(text) => fmt.write_fmt(format_args!("[U]{}[/U]", text))?, + BbCode::Link(text, url) => fmt.write_fmt(format_args!("[URL={}]{}[/URL]", url, text))?, + }; + + Ok(()) + } +} + +#[allow(dead_code)] +pub fn bold(text: &dyn Display) -> BbCode { + BbCode::Bold(text) +} + +#[allow(dead_code)] +pub fn italic(text: &dyn Display) -> BbCode { + BbCode::Italic(text) +} + +#[allow(dead_code)] +pub fn underline(text: &dyn Display) -> BbCode { + BbCode::Underline(text) +} + +#[allow(dead_code)] +pub fn link<'a>(text: &'a dyn Display, url: &'a str) -> BbCode<'a> { + BbCode::Link(text, url) +} |
