use std::any::type_name;
use std::marker::PhantomData;
use std::ops::Deref;
pub struct PriorityHigh;
pub struct PriorityLow;
impl Deref for PriorityHigh {
type Target = PriorityLow;
fn deref(&self) -> &Self::Target {
&PriorityLow
}
}
pub struct HelpQuery<T>(PhantomData<T>);
impl<T> HelpQuery<T> {
pub fn new() -> Self {
Self(PhantomData)
}
}
impl<T> Default for HelpQuery<T> {
fn default() -> Self {
Self::new()
}
}
pub trait CustomHelp {
fn custom_message() -> String;
}
pub trait HelpImplDefault {
fn get_message(&self, _p: &PriorityLow) -> String;
}
impl<T> HelpImplDefault for HelpQuery<T> {
fn get_message(&self, _: &PriorityLow) -> String {
let name = type_name::<T>().split("::").last().unwrap_or("Unknown");
format!("<{}>", name)
}
}
pub trait HelpImplCustom {
fn get_message(&self, _p: &PriorityHigh) -> String;
}
impl<T: CustomHelp> HelpImplCustom for HelpQuery<T> {
fn get_message(&self, _: &PriorityHigh) -> String {
<T as CustomHelp>::custom_message()
}
}