Crates.io | any-fn |
lib.rs | any-fn |
version | 0.6.3 |
created_at | 2025-01-20 11:36:41.582819+00 |
updated_at | 2025-09-20 04:26:31.171131+00 |
description | Dynamically-typed functions to represent any functions in Rust |
homepage | |
repository | https://github.com/raviqqe/any-fn |
max_upload_size | |
id | 1523816 |
size | 17,238 |
Dynamically-typed functions via core::any::Any
in Rust.
Due to combinatorial explosion, the dynamically-typed functions support only up to 6 arguments... 🥲
struct
use any_fn::{r#fn, value};
struct Foo {
foo: usize,
}
fn foo(x: usize, y: &mut Foo) {
y.foo = x;
}
let x = value(Foo { foo: 0 });
r#fn(foo).call(&[&value(42usize), &x]).unwrap();
assert_eq!(x.downcast_ref::<Foo>().unwrap().foo, 42);
use any_fn::{r#fn, Ref, value};
fn foo(x: usize, y: &usize, z: &mut usize) {
*z = x + *y;
}
let x = value(0usize);
r#fn::<(_, Ref<_>, _), _>(foo)
.call(&[&value(40usize), &value(2usize), &x])
.unwrap();
assert_eq!(x.downcast::<usize>().unwrap(), 42);