just/src/enclosure.rs
Casey Rodarmor 3de31b3c02
Remove misc.rs (#491)
Put everything that was in `misc.rs` into their own files, with some opportunistic
refactoring, because why not.
2019-10-09 01:40:40 -07:00

32 lines
541 B
Rust

use crate::common::*;
pub struct Enclosure<T: Display> {
enclosure: &'static str,
value: T,
}
impl<T: Display> Enclosure<T> {
pub fn tick(value: T) -> Enclosure<T> {
Enclosure {
enclosure: "`",
value,
}
}
}
impl<T: Display> Display for Enclosure<T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}{}{}", self.enclosure, self.value, self.enclosure)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tick() {
assert_eq!(Enclosure::tick("foo").to_string(), "`foo`")
}
}