use std::fmt;
use obfstr::{obfstr, obfstring, position};
pub enum Example {
Foo,
Bar,
Baz,
}
impl Example {
pub fn to_str1(&self) -> String {
match self {
Example::Foo => obfstring!("Foo"),
Example::Bar => obfstring!("Bar"),
Example::Baz => obfstring!("Baz"),
}
}
pub fn to_str2<R, F: FnMut(&str) -> R>(&self, mut f: F) -> R {
match self {
Example::Foo => f(obfstr!("Foo")),
Example::Bar => f(obfstr!("Bar")),
Example::Baz => f(obfstr!("Baz"))
}
}
pub fn to_str3<'a>(&self, buf: &'a mut [u8; 4]) -> &'a str {
match self {
Example::Foo => obfstr!(buf <- "Foo"),
Example::Bar => obfstr!(buf <- "Bar"),
Example::Baz => obfstr!(buf <- "Baz"),
}
}
pub const POOL: &'static str = concat!("Foo", "Bar", "Baz");
pub fn to_str4<'a>(&self, pool: &'a str) -> &'a str {
match self {
Example::Foo => &pool[position!(Example::POOL, "Foo")],
Example::Bar => &pool[position!(Example::POOL, "Bar")],
Example::Baz => &pool[position!(Example::POOL, "Baz")],
}
}
}
impl fmt::Display for Example {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.to_str2(|s| f.write_str(s))
}
}
fn main() {}