I would like to merge the two implementations of Printable into one below. Also, I'm concerned by the warning.
One implementation deals with references, the other without references. Anyone knows how to achieve one implementation for both? ChatGPT is hopeless.
In the long term, my framework should support function with multiple parameters, so being able to merge the two implementation will avoid exponential blowup. Thanks for your help.
use std::rc::Rc;
pub struct AStruct { pub i: i32 }
pub trait Printable {
fn print(&self);
}
impl<A, B> Printable for Rc<dyn for<'a> Fn(&'a A) -> B> {
fn print(&self) {
println!("function")
}
}
impl<A, B> Printable for Rc<dyn Fn(A) -> B> {
fn print(&self) {
println!("function")
}
}
pub fn test<T: Printable>() {}
pub fn call_test() {
test::<Rc<dyn for<'a> Fn(&'a AStruct) -> i32>>();
test::<Rc<dyn Fn(AStruct) -> i32>>();
}