thread_aware_macros/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Macros for the [`thread_aware`](https://docs.rs/thread_aware) crate.
5//!
6//! # Provided Derives
7//!
8//! * `#[derive(ThreadAware)]` – Auto-implements the `thread_aware::ThreadAware` trait by recursively
9//!   calling `transfer` on each field.
10
11#![doc(html_logo_url = "https://media.githubusercontent.com/media/microsoft/oxidizer/refs/heads/main/crates/thread_aware_macros/logo.png")]
12#![doc(
13    html_favicon_url = "https://media.githubusercontent.com/media/microsoft/oxidizer/refs/heads/main/crates/thread_aware_macros/favicon.ico"
14)]
15
16use proc_macro::TokenStream;
17use syn::{Path, parse_quote};
18
19// Documented in the thread_aware crate's reexport
20#[proc_macro_derive(ThreadAware, attributes(thread_aware))]
21#[cfg_attr(test, mutants::skip)]
22pub fn derive_transfer(input: TokenStream) -> TokenStream {
23    let root_path: Path = parse_quote!(::thread_aware);
24    thread_aware_macros_impl::derive_thread_aware(input.into(), &root_path).into()
25}