The following doesnt work (yet) in Mojo it seems
trait Printer:
fn print_it(self,text:String):
...
@value
struct BoringPrinter(Printer):
fn print_it(self,text:String):
print(text)
fn lets_print(p:Printer,text:String):
p.print_it(text)
fn main():
var bp = BoringPrinter()
lets_print(bp,"let's sing a song")
i get the following error:
error: invalid call to 'lets_print': argument #0 cannot be converted from 'BoringPrinter' to 'Printer'
有没有办法在 Mojo 中实现我在这里尝试做的事情。由于我们还没有继承,我想使用依赖注入,但如果没有这个,我感觉很糟糕。
对此的任何建议都非常感谢。不幸的是,不知道如何实现这一点让我无法思考像 Mojo 项目这样更有趣的框架