rust/macros/module.rs

Source file repositories/reference/linux-study-clean/rust/macros/module.rs

File Facts

System
Linux kernel
Corpus path
rust/macros/module.rs
Extension
.rs
Size
22681 bytes
Lines
654
Domain
Rust Kernel Layer
Bucket
Rust API Membrane
Inferred role
Rust Kernel Layer: exported/initcall integration point
Status
integration 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

struct Parameter {
    name: Ident,
    ptype: Ident,
    default: Expr,
    description: LitStr,
}

impl Parse for Parameter {
    fn parse(input: ParseStream<'_>) -> Result<Self> {
        let name = input.parse()?;
        input.parse::<Token![:]>()?;
        let ptype = input.parse()?;

        let fields;
        braced!(fields in input);

        parse_ordered_fields! {
            from fields;
            default [required] => fields.parse()?,
            description [required] => fields.parse()?,
        }

        Ok(Self {
            name,
            ptype,
            default,
            description,
        })
    }
}

pub(crate) struct ModuleInfo {
    type_: Type,
    license: AsciiLitStr,
    name: AsciiLitStr,
    authors: Option<Punctuated<AsciiLitStr, Token![,]>>,
    description: Option<LitStr>,
    alias: Option<Punctuated<AsciiLitStr, Token![,]>>,
    firmware: Option<Punctuated<AsciiLitStr, Token![,]>>,
    imports_ns: Option<Punctuated<AsciiLitStr, Token![,]>>,
    params: Option<Punctuated<Parameter, Token![,]>>,
}

impl Parse for ModuleInfo {
    fn parse(input: ParseStream<'_>) -> Result<Self> {
        parse_ordered_fields!(
            from input;
            type as type_ [required] => input.parse()?,
            name [required] => input.parse()?,
            authors => {
                let list;
                bracketed!(list in input);
                Punctuated::parse_terminated(&list)?
            },
            description => input.parse()?,
            license [required] => input.parse()?,
            alias => {
                let list;
                bracketed!(list in input);
                Punctuated::parse_terminated(&list)?
            },
            firmware => {
                let list;
                bracketed!(list in input);
                Punctuated::parse_terminated(&list)?
            },
            imports_ns => {
                let list;
                bracketed!(list in input);
                Punctuated::parse_terminated(&list)?
            },
            params => {
                let list;
                braced!(list in input);
                Punctuated::parse_terminated(&list)?
            },
        );

        Ok(ModuleInfo {
            type_,
            license,
            name,
            authors,
            description,
            alias,
            firmware,
            imports_ns,
            params,
        })
    }

Annotation

Implementation Notes