Trait T is not implemented for Box. How to solve?

⚓ rust    📅 2025-07-03    👤 surdeus    👁️ 2      

surdeus

Hello.

This code fails to compile with the following error:

error[E0277]: expected a `FnOnce()` closure, found `dyn CallOnce`

In the end, I want to be able to pass Box<dyn CallOnce> to a function that accepts impl CallOnce, while also having implemented <T: FnOnce> CallOnce for T.

How to fix the code?

Also a question of secondary importance, why Box<dyn T> does not automatically implement T? Would there be any problems with that?

2 posts - 2 participants

Read full topic

🏷️ rust_feed