Sha256: c0204a41d747889cfd6723f4f3bf4aa2f9f868c288738d29cc6229de4260debf

Contents?: true

Size: 953 Bytes

Versions: 19

Compression:

Stored size: 953 Bytes

Contents

use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
use syn::{Error, ItemFn};

pub fn expand(name: Option<String>, input: ItemFn) -> Result<TokenStream, Error> {
    let crate_name = match name {
        Some(v) => v,
        None => match std::env::var("CARGO_PKG_NAME") {
            Ok(v) => v,
            Err(_) => {
                return Err(Error::new(
                    Span::call_site(),
                    r#"missing (name = "...") attribute"#,
                ))
            }
        },
    };

    let extern_init_name = Ident::new(
        &format!("Init_{}", crate_name.replace('-', "_")),
        Span::call_site(),
    );
    let init_name = input.sig.ident.clone();

    Ok(quote! {
        #input

        #[allow(non_snake_case)]
        #[no_mangle]
        pub unsafe extern "C" fn #extern_init_name() {
            use magnus::method::{Init, RubyInit};
            #init_name.call_handle_error()
        }
    })
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-28.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-27.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-26.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-25.0.2 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-25.0.1 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-25.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-24.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-23.0.2 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-22.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-21.0.1 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-20.0.2 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-20.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-18.0.3 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-17.0.1 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-17.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-16.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-15.0.1 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs
wasmtime-15.0.0 ./ext/cargo-vendor/magnus-macros-0.6.0/src/init.rs