|
|
|
|
|
by benschulz
1612 days ago
|
|
Sorry, based on the replies I'm getting I did not make myself clear. I only want to use Either in cases like the following. fn some_func() -> impl SomeTrait {
if some_condition {
Either::Left(a)
} else {
Either::Right(b)
}
}
Both a and b will implement SomeTrait which is all callers care about. However, because they're structurally different they must be wrapped in an Either that delegates all methods from SomeTrait to a or b respectively. |
|
For object-safe traits where this would be possible, you can at least do this at the cost of an allocation, as you probably know: