Expand description
§Anythingy
This is a work-in-progess project and not for production use.
A library for dynamic typing.
It’s main feature is the Thing
type, that works similar to Box<dyn Any>
, but can be sized at compile time.
Additonal type maps for storing objects of different types are provided:
AnyMap
using aHashMap
for storing a large number of different types.SmallAnyMap
using aVec
for storing a small number of different types.
§Example
let number_thing: Thing<24> = Thing::new(42u64);
let sting_thing: Thing<24> = Thing::new(String::from("Hello there"));
let bytes_thing: Thing<24> = Thing::new(Vec::from(b"so uncivilized"));
let number = number_thing.get::<u64>();
assert_eq!(number, 42);
let string = sting_thing.get::<String>();
assert_eq!(&string, "Hello there");
let bytes = bytes_thing.get::<Vec<u8>>();
assert_eq!(&bytes, b"so uncivilized");
Structs§
- AnyMap
- A map for storing type erased values.
- Small
AnyMap - A map for storing type erased values.
For a small number of entries, using a
Vec
as underlying datastructure is more efficient. - Thing
- A Structure for storing type-erased values. Similar to
Box<dyn Any>
it can store values of any type.
Constants§
- DEFAULT_
THING_ SIZE - Default size of
Thing
. Choosen to be 3xstd::mem::size_of<usize>()
, to facilitateVec
/String
without boxing them, to prevent double pointers.