Generic callback function - clunky version

⚓ Rust    📅 2025-08-19    👤 surdeus    👁️ 6      

surdeus

Ref:

Rust does not allow a generic type parameter in a function parameter. At least not yet.
I need to do that, though, so here's a solution involving Box, RefCell, and run-time borrow().
It works, but is a bit clunky. Suggestions?

I tried using just RefCell, which, like Box, takes ownership of its content. But RefCell<&dyn mut Any> doesn't work.

(Use case: passing a mutable link to a MySQL connection into something that uses it repeatedly.)

1 post - 1 participant

Read full topic

🏷️ Rust_feed