use std::fmt;
impl<'a> TargetSession<'a> {
pub fn new(target_name: &'a str) -> Self {
TargetSession::StartName(target_name)
}
pub fn exact_name(name: &'a str) -> Self {
TargetSession::ExactName(name)
}
pub fn start_name(name: &'a str) -> Self {
TargetSession::StartName(name)
}
pub fn fn_match(name: &'a str) -> Self {
TargetSession::FnMatch(name)
}
pub fn raw(name: &'a str) -> Self {
TargetSession::Raw(name)
}
}
#[derive(Debug)]
pub enum TargetSession<'a> {
Id(usize),
ExactName(&'a str),
StartName(&'a str),
FnMatch(&'a str),
Raw(&'a str),
}
impl<'a> fmt::Display for TargetSession<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TargetSession::Id(id) => write!(f, "${}", id),
TargetSession::ExactName(name) => write!(f, "={}", name),
TargetSession::StartName(name) => f.write_str(name),
TargetSession::FnMatch(name) => f.write_str(name),
TargetSession::Raw(name) => f.write_str(name),
}
}
}