Why AnyHistory
is an enum and not a wrapper around Box<dyn History>
#2933
Answered
by
futursolo
Neo-Ciber94
asked this question in
Q&A
-
I'm browsing through the repository to know how can I implement by own router, and I found this: /// A [`History`] that provides a universial API to the underlying history type.
#[derive(Clone, PartialEq, Debug)]
pub enum AnyHistory {
/// A Browser History.
Browser(BrowserHistory),
/// A Hash History
Hash(HashHistory),
/// A Memory History
Memory(MemoryHistory),
} I think this make hard to add your own implementation, why pub struct AnyHistory {
imp: Box<dyn History>
} |
Beta Was this translation helpful? Give feedback.
Answered by
futursolo
Oct 22, 2022
Replies: 1 comment
-
Boxing a struct involves an additional allocation and using enumerate can avoid the allocation. The |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
futursolo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Boxing a struct involves an additional allocation and using enumerate can avoid the allocation.
The
History
trait is also not object safe (required for boxing) as it uses generics on its methods.