79307938

Date: 2024-12-25 16:13:44
Score: 0.5
Natty:
Report link

It’s generally not a good idea to emulate features from other languages in Rust. When you create a boxed trait object, you incur two types of overhead: 1. Pointer indirection via the Box, which stores the value on the heap. 2. Dynamic dispatch through the vtable to resolve the method call.

so it’s best to avoid it unless absolutely necessary.

Additionally, when you box a type T, you’re moving it to the heap, which means that T cannot have references, because after moving something on heap, rust cannot guarantee that referenced value will outlive the T, so this operation is not allowed in safe rust. As a result, if your iterator implementations contain references to other data, they cannot be boxed, as this would lead violate rust's safety guarantees.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Babur Makhmudov