Expand description

Mono macro

This crate provides the #[mono] macro to force a generic function to be monomorphizied with give types.

Pair with share-generics mode in rustc, this can result less code, for details see https://github.com/rust-lang/rust/pull/48779.

[dependencies]
mono-macro = "1.0"

Usage

Since we are monomorphizing ourselves, you are required to spell out the static dispatch handly:

In a bare function case,

#[mono(T = i32, U = i64)]
fn func<T, U>(t: T, u: U) {
    ...
}

it will be expanded to:

pub const _: *const () = (&foo::<i32, i64>) as *const _ as _;
fn func<T, U>(t: T, u: U) {
    ...
}

Attribute Macros

Apply this macro on a generic function will cast the function pointer with given type into pointer, which forces this function to be monomorphized.