Questions tagged [enum-dispatch]
4 questions
1
vote
0 answers
TryInto trait asks for more type annotations even though all annotations are in place
I have the following code (constrained example). There is a serial protocol, modelled with Command and Responce enums using enum_dispatch crate - every variant in enum is represented with a struct. Transport struct taskes care of serialization,…

ASMik09
- 33
- 5
0
votes
0 answers
Calling enum_dispatch'd instances of structs from main, outside of crate or file
If run without changes, test_method() is called correctly for both variants in the function get_test_vector():
//! handler.rs
use enum_dispatch::enum_dispatch;
#[enum_dispatch]
trait CommonTrait {
fn test_method(&self)…

TheAlmightyD
- 31
- 3
0
votes
1 answer
How to use two traits with enum_dispatch?
I've tried:
#[enum_dispatch(BarTrait, BazTrait)]
pub enum Foo {
VariantZero,
...
}
It seems to ignore any traits after the first, silently.
This causes errors, as in this case the compiler doesn't seem to believe that Foo implements…

fadedbee
- 42,671
- 44
- 178
- 308
0
votes
1 answer
How to use composition instead of inheritance? Enum_dispatch?
I know I should use composition instead of inheritance.
In Java/C++, I have an abstract base class Vehicle (with properties and common methods) and classes which implement this, such as Car and Bike.
I've found enum_dispatch, which does a great job…

fadedbee
- 42,671
- 44
- 178
- 308