mirror of
https://github.com/Noratrieb/the-good-stuff.git
synced 2026-01-16 09:35:01 +01:00
move
This commit is contained in:
parent
1721d6a45a
commit
9bab547bcf
20 changed files with 1305 additions and 0 deletions
46
old-stuff/pm/src/lib.rs
Normal file
46
old-stuff/pm/src/lib.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use proc_macro::TokenStream;
|
||||
|
||||
mod safe_extern;
|
||||
mod scratch;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn scratch_space(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
scratch::scratch_space(attr, input)
|
||||
}
|
||||
|
||||
/// # safe-extern
|
||||
///
|
||||
/// Mark foreign functions as to be safe to call.
|
||||
///
|
||||
/// ```ignore
|
||||
/// #[safe_extern]
|
||||
/// extern "Rust" {
|
||||
/// fn add(a: u8, b: u8) -> u8;
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(add(1, 2), 3);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// It works by expanding the above to this
|
||||
///
|
||||
/// ```ignore
|
||||
/// extern "Rust" {
|
||||
/// #[link_name = "add"]
|
||||
/// fn _safe_extern_inner_add(a: u8, b: u8) -> u8;
|
||||
/// }
|
||||
/// fn add(a: u8, b: u8) -> u8 {
|
||||
/// unsafe { _safe_extern_inner_add(a, b) }
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(add(1, 2), 3);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// This is of course unsound and the macro needs to be `unsafe` somehow but I can't be bothered with that right now lol.
|
||||
#[proc_macro_attribute]
|
||||
pub fn safe_extern(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
safe_extern::safe_extern(attr, input)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue