pub_just/
enclosure.rs

1use super::*;
2
3pub struct Enclosure<T: Display> {
4  enclosure: &'static str,
5  value: T,
6}
7
8impl<T: Display> Enclosure<T> {
9  pub fn tick(value: T) -> Enclosure<T> {
10    Self {
11      enclosure: "`",
12      value,
13    }
14  }
15}
16
17impl<T: Display> Display for Enclosure<T> {
18  fn fmt(&self, f: &mut Formatter) -> fmt::Result {
19    write!(f, "{}{}{}", self.enclosure, self.value, self.enclosure)
20  }
21}
22
23#[cfg(test)]
24mod tests {
25  use super::*;
26
27  #[test]
28  fn tick() {
29    assert_eq!(Enclosure::tick("foo").to_string(), "`foo`");
30  }
31}