| Crates.io | fn_meta |
| lib.rs | fn_meta |
| version | 0.8.0 |
| created_at | 2021-04-26 01:58:41.83756+00 |
| updated_at | 2025-03-17 06:08:48.1233+00 |
| description | Returns metadata about a function at runtime. |
| homepage | |
| repository | https://github.com/azriel91/fn_meta |
| max_upload_size | |
| id | 389540 |
| size | 62,632 |
Returns metadata about a function at runtime.
Currently this includes the TypeIds of function parameters.
This includes a FnMetadata struct and FnMetadataExt trait. FnMetadataExt adds the .metadata() function on functions and closures to return a FnMetadata, whose implementation returns function metadata at runtime.
Add the following to Cargo.toml
fn_meta = "0.8.0"
# or
fn_meta = { version = "0.8.0", features = ["fn_meta_ext"] }
Code:
use core::any::TypeId;
use fn_meta::{FnMetaDyn, FnMetadataExt};
fn f1(_: &S0, _: &mut S1, _: &S2) -> () {}
let fn_metadata = f1.metadata();
assert_eq!(
[TypeId::of::<S0>(), TypeId::of::<S2>()],
fn_metadata.borrows().as_slice()
);
assert_eq!([TypeId::of::<S1>()], fn_metadata.borrow_muts().as_slice());
struct S0;
struct S1;
struct S2;
"fn_meta_ext":Enables the FnMeta and FnMetaExt traits. FnMetaExt adds the .meta() function on functions and closures to return a Box<dyn FnMeta>, which is the dynamic dispatch analog to FnMetadata.
"high_arg_count":Raises the number of arguments that FnMetaExt and FnMetadataExt are implemented for from 6 to 8.
This is feature gated because compilation time increasing significantly with higher numbers of arguments -- as much as from 1.5 seconds for 6 arguments to 8 seconds for 8 arguments.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.