#stack #type-erasure #any #no-std

no-std stack-any

A library that provides a type that owns same size type on the stack for type erasure

3 releases

0.1.2 Jun 29, 2024
0.1.1 Jun 29, 2024
0.1.0 Jun 27, 2024

#316 in Memory management

Download history 355/week @ 2024-06-23 76/week @ 2024-06-30 1/week @ 2024-07-07 27/week @ 2024-07-28 1/week @ 2024-08-25 1/week @ 2024-09-01 20/week @ 2024-09-15 26/week @ 2024-09-22 62/week @ 2024-09-29 4/week @ 2024-10-06

112 downloads per month
Used in ecs-tiny

MIT license

7KB
71 lines

stack-any

crates.io doc.rs

A library that provides a type that owns same size type on the stack for type erasure.

Usage

let mut stacks = [
    stack_any::stack_any!(Vec<i32>, vec![]),
    stack_any::stack_any!(Vec<char>, vec![]),
];

stacks[0].downcast_mut::<Vec<i32>>().unwrap().push(5);
stacks[1].downcast_mut::<Vec<char>>().unwrap().push('x');

assert_eq!(stacks[0].downcast_ref(), Some(&vec![5]));
assert_eq!(stacks[1].downcast_ref(), Some(&vec!['x']));

lib.rs:

stack-any

A library that provides a type that owns same size type on the stack for type erasure.

Usage

let mut stacks = [
    stack_any::stack_any!(Vec<i32>, vec![]),
    stack_any::stack_any!(Vec<char>, vec![]),
];

stacks[0].downcast_mut::<Vec<i32>>().unwrap().push(5);
stacks[1].downcast_mut::<Vec<char>>().unwrap().push('x');

assert_eq!(stacks[0].downcast_ref(), Some(&vec![5]));
assert_eq!(stacks[1].downcast_ref(), Some(&vec!['x']));

No runtime deps