rust/zerocopy/benches/formats/coco_dynamic_padding.rs

Source file repositories/reference/linux-study-clean/rust/zerocopy/benches/formats/coco_dynamic_padding.rs

File Facts

System
Linux kernel
Corpus path
rust/zerocopy/benches/formats/coco_dynamic_padding.rs
Extension
.rs
Size
589 bytes
Lines
25
Domain
Rust Kernel Layer
Bucket
Rust API Membrane
Inferred role
Rust Kernel Layer: implementation source
Status
source implementation candidate

Why This File Exists

Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.

Dependency Surface

Detected Declarations

Annotated Snippet

use zerocopy_derive::*;

// The only valid value of this type are the bytes `0xC0C0`.
#[derive(TryFromBytes, KnownLayout, Immutable)]
#[repr(u16)]
pub enum C0C0 {
    _XC0C0 = 0xC0C0,
}

#[derive(FromBytes, KnownLayout, Immutable, SplitAt)]
#[repr(C, align(4))]
pub struct Packet<Magic> {
    magic_number: Magic,
    milk: u8,
    mug_size: u8,
    temperature: [u8; 5],
    marshmallows: [[u8; 3]],
}

/// A packet begining with the magic number `0xC0C0`.
pub type CocoPacket = Packet<C0C0>;

/// A packet beginning with any two initialized bytes.
pub type LocoPacket = Packet<[u8; 2]>;

Annotation

Implementation Notes