struct Item
{
count: usize,
}
impl Item
{
pub fn count(&self) -> usize
{
return self.count;
}
}
impl From<&str> for Item
{
fn from(value: &str) -> Self
{
return Self { count: value.len() };
}
}
struct Factory;
impl Factory
{
pub fn new() -> Self
{
return Self {};
}
pub fn get<'a, T>(&'a self, value: &'a str) -> T
where T: From<&'a str>
{
let value_parsed = value.chars().rev().collect::<String>();
return T::from(&value_parsed);
}
}
pub fn main()
{
let factory = Factory::new();
println!("{}", factory.get::<Item>("hi").count());
}