pub trait Configure: Clone + Default {
#[inline]
fn pretty_print(&self) -> bool {
false
}
}
#[derive(Debug, Clone)]
pub struct Config {
pretty_print: bool,
}
impl Config {
pub fn new() -> Self {
Self::default()
}
pub fn set_pretty_print(&mut self, pretty_print: bool) {
self.pretty_print = pretty_print;
}
}
impl Configure for Config {
fn pretty_print(&self) -> bool {
self.pretty_print
}
}
impl Default for Config {
fn default() -> Self {
Self {
pretty_print: false,
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn config_doesnt_pretty_print_by_default() {
assert_eq!(Config::default().pretty_print(), false);
}
#[test]
fn config_pretty_print_behavior_can_be_changed() {
let mut config = Config::default();
config.set_pretty_print(true);
assert_eq!(config.pretty_print(), true);
config.set_pretty_print(false);
assert_eq!(config.pretty_print(), false);
}
}