rust/zerocopy/benches/formats/coco_static_size.rs

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

File Facts

System
Linux kernel
Corpus path
rust/zerocopy/benches/formats/coco_static_size.rs
Extension
.rs
Size
727 bytes
Lines
28
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, IntoBytes)]
#[repr(u16)]
pub enum C0C0 {
    _XC0C0 = 0xC0C0,
}

macro_rules! define_packet {
    ($name: ident, $trait: ident, $leading_field: ty) => {
        #[derive($trait, KnownLayout, Immutable, IntoBytes)]
        #[repr(C, align(2))]
        pub struct $name {
            magic_number: $leading_field,
            mug_size: u8,
            temperature: u8,
            marshmallows: [u8; 2],
        }
    };
}

/// Packet begins with bytes 0xC0C0.
define_packet!(CocoPacket, TryFromBytes, C0C0);

/// Packet begins with any two bytes.
define_packet!(LocoPacket, FromBytes, [u8; 2]);

Annotation

Implementation Notes