pub struct Frame {
pub bytes: Bytes,
}Expand description
IPv4 / TCP / UDP frame as it crosses the virtio-net boundary. Pure payload — the virtio-net header is consumed by the frontend before frames reach the backend (and prepended on RX).
Storage is bytes::Bytes (immutable, shared, refcounted) per I-NET-4 in
30-networking.md § 7:
the hot path is allocation-free for clones (Bytes::clone is just a
refcount bump). New frames are typically built via FramePool::acquire
→ fill BytesMut → Frame::from_buf.
Fields§
§bytes: BytesRaw bytes (Ethernet header + IP + payload).
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn from_slice(slice: &[u8]) -> Self
pub fn from_slice(slice: &[u8]) -> Self
Build a frame from a slice. Allocates a fresh Bytes — call sites
that own the buffer should prefer Frame::from_buf which avoids the
copy.
Sourcepub fn from_buf(buf: BytesMut) -> Self
pub fn from_buf(buf: BytesMut) -> Self
Build a frame by freezing a bytes::BytesMut into the Bytes
shape. The caller’s exclusive write access ends here; subsequent
readers go through the immutable Bytes.
Sourcepub const fn from_bytes(bytes: Bytes) -> Self
pub const fn from_bytes(bytes: Bytes) -> Self
Build a frame directly from a bytes::Bytes handle. Useful when
the caller already has a refcounted buffer (e.g. a parser that hands
out a slice of a larger pre-allocated buffer).