mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
So far it is quite common to put the `AnyUnboundSocket` in an enum variant, e.g. the following code snippet. ```rust enum Inner { Unbound(AlwaysSome<Box<AnyUnboundSocket>>), Bound(AlwaysSome<Arc<AnyBoundSocket>>), // ... } ``` However, this pattern is very memory inefficient because the size difference between two enum variants is significant. The size of `AnyUnboundSocket` is much larger than the size of `Arc<AnyBoundSocket>`, where the latter is simply a pointer and a reference counter. In fact, we're about to trigger Clippy's large_enum_variant warning. We're just below its threshold, so the warning doesn't appear. The solution is simple: If we put `AnyBoundSocket` in `Arc`, we should also put `AnyUnboundSocket` in `Box`. This way the sizes of different enum variants will be similar.