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,
|
2020-02-10 20:07:06 -08: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() {
|
|
|
|
assert_eq!(Enclosure::tick("foo").to_string(), "`foo`")
|
|
|
|
}
|
|
|
|
}
|