Giter Site home page Giter Site logo

williamvenner / fn_has_this Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 3 KB

✨ A proc attribute macro that adds a this argument to a function

Home Page: https://crates.io/crates/fn_has_this

License: MIT License

Rust 100.00%
rust proc-macro proc-macro-attributes this argument arg ffi conditional-compilation

fn_has_this's Introduction

crates.io

fn_has_this

A proc attribute macro that adds a this argument to a function.

This macro is well suited for conditional compilation. For example, some compilers will optimize away a this argument in a non-static function if it is unused, sometimes depending on calling convention. This macro makes it easy to conditionally compile your Rust programs to interact over FFI with functions compiled in this way.

Example

#[macro_use]
extern crate fn_has_this;

use core::ffi::c_void;

#[has_this("*mut c_void")] // Will create an argument called `this` in the function
pub unsafe extern "fastcall" fn print_pointer() {
    println!("{:x?}", this);
}

#[has_this("me: *mut c_void")] // You can also specify a custom name for the `this` argument
pub unsafe extern "thiscall" fn print_pointer() {
    println!("{:x?}", me);
}

#[cfg_attr(target_os = "windows", has_this("me: *mut c_void"))] // Using `cfg_attr`, you can conditionally compile this attribute macro
pub unsafe extern "thiscall" fn print_pointer() {
    println!("{:x?}", me);
}

fn_has_this's People

Contributors

williamvenner avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.