2020-01-15 02:16:13 -08:00
|
|
|
// `Self` cannot be used where type takes generic arguments
|
|
|
|
#![allow(clippy::use_self)]
|
|
|
|
|
2019-10-09 01:40:40 -07:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
pub struct Enclosure<T: Display> {
|
|
|
|
enclosure: &'static str,
|
2021-09-16 06:44:40 -07:00
|
|
|
value: T,
|
2019-10-09 01:40:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Display> Enclosure<T> {
|
|
|
|
pub fn tick(value: T) -> Enclosure<T> {
|
2020-01-15 02:16:13 -08:00
|
|
|
Self {
|
2019-10-09 01:40:40 -07:00
|
|
|
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() {
|
2021-05-07 00:14:38 -07:00
|
|
|
assert_eq!(Enclosure::tick("foo").to_string(), "`foo`");
|
2019-10-09 01:40:40 -07:00
|
|
|
}
|
|
|
|
}
|