16 releases (5 breaking)

Uses new Rust 2024

0.6.3 Sep 20, 2025
0.6.2 Sep 19, 2025
0.6.1 Jan 26, 2025
0.5.2 Jan 24, 2025
0.1.3 Jan 20, 2025

#603 in Algorithms

Download history 248/week @ 2025-08-18 190/week @ 2025-08-25 150/week @ 2025-09-01 194/week @ 2025-09-08 484/week @ 2025-09-15 363/week @ 2025-09-22 285/week @ 2025-09-29 103/week @ 2025-10-06 167/week @ 2025-10-13 178/week @ 2025-10-20 134/week @ 2025-10-27 265/week @ 2025-11-03 185/week @ 2025-11-10 171/week @ 2025-11-17 253/week @ 2025-11-24 599/week @ 2025-12-01

1,254 downloads per month
Used in 3 crates

MIT license

14KB
341 lines

any-fn

GitHub Action Crate License

Dynamically-typed functions via core::any::Any in Rust.

Due to combinatorial explosion, the dynamically-typed functions support only up to 6 arguments... 🥲

Examples

Mutating a 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);

Calling a function with unboxed, immutable reference, and mutable reference arguments

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);

License

MIT

No runtime deps