rust/macros/concat_idents.rs

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

File Facts

System
Linux kernel
Corpus path
rust/macros/concat_idents.rs
Extension
.rs
Size
681 bytes
Lines
37
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

// SPDX-License-Identifier: GPL-2.0

use proc_macro2::{
    Ident,
    TokenStream,
    TokenTree, //
};
use syn::{
    parse::{
        Parse,
        ParseStream, //
    },
    Result,
    Token, //
};

pub(crate) struct Input {
    a: Ident,
    _comma: Token![,],
    b: Ident,
}

impl Parse for Input {
    fn parse(input: ParseStream<'_>) -> Result<Self> {
        Ok(Self {
            a: input.parse()?,
            _comma: input.parse()?,
            b: input.parse()?,
        })
    }
}

pub(crate) fn concat_idents(Input { a, b, .. }: Input) -> TokenStream {
    let res = Ident::new(&format!("{a}{b}"), b.span());
    TokenStream::from_iter([TokenTree::Ident(res)])
}

Annotation

Implementation Notes