Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/csmoe/mono-macro
Force monomorphizing on a generic function.
https://github.com/csmoe/mono-macro
Last synced: 21 days ago
JSON representation
Force monomorphizing on a generic function.
- Host: GitHub
- URL: https://github.com/csmoe/mono-macro
- Owner: csmoe
- License: other
- Created: 2022-03-05T17:02:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-08T12:23:09.000Z (over 1 year ago)
- Last Synced: 2024-11-16T12:36:45.351Z (about 2 months ago)
- Language: Rust
- Homepage: https://docs.rs/mono-macro
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Mono macro
==================This crate provides the `#[mono]` macro to force a generic function to be monomorphizied with given types.
Pair with `share-generics` mode in rustc, this can result less code, for details see https://github.com/rust-lang/rust/pull/48779.
```toml
[dependencies]
mono-macro = "0.1"
```
## Usage
Since we are monomorphizing ourselves, you are required to spell out the static dispatch manually:
In a bare function case,
```rust
#[mono(T = i32, U = i64)]
fn func(t: T, u: U) {
...
}
```it will be expanded to:
```rust
pub const _: *const () = (&foo::) as *const _ as _;
fn func(t: T, u: U) {
...
}```
For more complicated case, use `mono_macro!` instead:
```rust
trait Tr {
fn foo(&self, _t: T) {}
}struct Foo<'a> {
t: &'a str,
}impl<'a, T> Tr for Foo<'a> {
fn foo(&self, _t: T) {}
}mono_macro!( as Tr>::foo);
```this will expand to:
```rust
trait Tr {
fn foo(&self, _t: T) {}
}struct Foo<'a> {
t: &'a str,
}impl<'a, T> Tr for Foo<'a> {
fn foo(&self, _t: T) {}
}pub const _: *const () = (& as Tr>::foo) as *const _ as _;
```#### License
Licensed under either of Apache License, Version
2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.