Crate anythingy

Source
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 a HashMap for storing a large number of different types.
  • SmallAnyMap using a Vec 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.
SmallAnyMap
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 3x std::mem::size_of<usize>(), to facilitate Vec/String without boxing them, to prevent double pointers.