rust/proc-macro2/wrapper.rs
Source file repositories/reference/linux-study-clean/rust/proc-macro2/wrapper.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/proc-macro2/wrapper.rs- Extension
.rs- Size
- 31105 bytes
- Lines
- 987
- 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.
- Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function newfunction pubfunction fromfunction Somefunction size_hintfunction pubfunction Somefunction pubfunction fmtfunction Okfunction pubfunction pub
Annotated Snippet
fn evaluate_now(&mut self) {
// If-check provides a fast short circuit for the common case of `extra`
// being empty, which saves a round trip over the proc macro bridge.
// Improves macro expansion time in winrt by 6% in debug mode.
if !self.extra.is_empty() {
self.stream.extend(self.extra.drain(..));
}
}
fn into_token_stream(mut self) -> proc_macro::TokenStream {
self.evaluate_now();
self.stream
}
}
impl TokenStream {
pub(crate) fn new() -> Self {
if inside_proc_macro() {
TokenStream::Compiler(DeferredTokenStream::new(proc_macro::TokenStream::new()))
} else {
TokenStream::Fallback(fallback::TokenStream::new())
}
}
pub(crate) fn from_str_checked(src: &str) -> Result<Self, LexError> {
if inside_proc_macro() {
Ok(TokenStream::Compiler(DeferredTokenStream::new(
proc_macro::TokenStream::from_str_checked(src)?,
)))
} else {
Ok(TokenStream::Fallback(
fallback::TokenStream::from_str_checked(src)?,
))
}
}
pub(crate) fn is_empty(&self) -> bool {
match self {
TokenStream::Compiler(tts) => tts.is_empty(),
TokenStream::Fallback(tts) => tts.is_empty(),
}
}
fn unwrap_nightly(self) -> proc_macro::TokenStream {
match self {
TokenStream::Compiler(s) => s.into_token_stream(),
TokenStream::Fallback(_) => mismatch(line!()),
}
}
fn unwrap_stable(self) -> fallback::TokenStream {
match self {
TokenStream::Compiler(_) => mismatch(line!()),
TokenStream::Fallback(s) => s,
}
}
}
impl Display for TokenStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TokenStream::Compiler(tts) => Display::fmt(&tts.clone().into_token_stream(), f),
TokenStream::Fallback(tts) => Display::fmt(tts, f),
}
}
}
impl From<proc_macro::TokenStream> for TokenStream {
fn from(inner: proc_macro::TokenStream) -> Self {
TokenStream::Compiler(DeferredTokenStream::new(inner))
}
}
impl From<TokenStream> for proc_macro::TokenStream {
fn from(inner: TokenStream) -> Self {
match inner {
TokenStream::Compiler(inner) => inner.into_token_stream(),
TokenStream::Fallback(inner) => {
proc_macro::TokenStream::from_str_unchecked(&inner.to_string())
}
}
}
}
impl From<fallback::TokenStream> for TokenStream {
fn from(inner: fallback::TokenStream) -> Self {
TokenStream::Fallback(inner)
}
}
Annotation
- Detected declarations: `function new`, `function pub`, `function from`, `function Some`, `function size_hint`, `function pub`, `function Some`, `function pub`, `function fmt`, `function Ok`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.