#[non_exhaustive]pub enum AnyBackend {
Boxed(BoxedBackend),
}Expand description
Enum dispatch backend for eliminating vtable indirection on the hot path.
§Enum Dispatch vs Vtable
This enum uses enum dispatch (also known as “inline dispatch”) to avoid vtable lookups for the built-in backends:
| Approach | Pros | Cons |
|---|---|---|
Enum dispatch (AnyBackend) | Zero-cost: no vtable indirection, better inlining, cache-friendly | Closed set of variants |
Vtable (Box<dyn Backend>) | Open for extension, dynamic plugin loading | Virtual call overhead, harder to inline |
§Migration Path: Adding a New Backend (e.g., kqueue)
- Create a new crate:
kqueue/Cargo.toml - Implement the trait:
impl Backend for KqueueBackend { ... } - Add the variant (optional, for zero-cost):
// In core/src/backend.rs pub enum AnyBackend { Boxed(BoxedBackend), Kqueue(wireshift_kqueue::KqueueBackend), // Zero-cost variant } - Feature-flag it in the workspace Cargo.toml:
[features] kqueue = ["dep:wireshift-kqueue"]
§Send + Sync Guarantees
AnyBackend is Send + Sync because every variant contains only Send + Sync
types. The compiler automatically derives these traits - no unsafe impl needed.
If a future variant breaks this contract, the compiler will reject it.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Boxed(BoxedBackend)
A boxed backend (legacy or third-party).
Use this for foreign backends that aren’t part of the core wireshift workspace. For built-in backends, prefer dedicated variants for zero-cost dispatch.
Implementations§
Source§impl AnyBackend
impl AnyBackend
Sourcepub fn from_boxed(backend: BoxedBackend) -> Self
pub fn from_boxed(backend: BoxedBackend) -> Self
Wrap a boxed backend into the enum dispatch.
Trait Implementations§
Source§impl Backend for AnyBackend
impl Backend for AnyBackend
Auto Trait Implementations§
impl !RefUnwindSafe for AnyBackend
impl !UnwindSafe for AnyBackend
impl Freeze for AnyBackend
impl Send for AnyBackend
impl Sync for AnyBackend
impl Unpin for AnyBackend
impl UnsafeUnpin for AnyBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more