use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
use ast::Format;
use {Args, Message};
pub struct SelectFormat<K> {
#[allow(dead_code)]
variable_name: String,
#[allow(dead_code)]
mappings: HashMap<K, Message>,
default: Message,
}
impl<K> SelectFormat<K>
where K: Eq + Hash
{
pub fn new(variable_name: &str, default: Message) -> Self {
SelectFormat {
variable_name: variable_name.to_string(),
mappings: HashMap::<K, Message>::new(),
default: default,
}
}
pub fn map(mut self, value: K, message: Message) -> Self {
self.mappings.insert(value, message);
self
}
}
impl<K> Format for SelectFormat<K> {
fn format_message_part(&self, stream: &mut fmt::Write, args: &Args) -> fmt::Result {
try!(self.default.format_message(stream, args));
Ok(())
}
}