#typing #dynamic #thing #value #boxing #box-dyn

anythingy

A library for dynamic typing

2 releases

0.1.1 Mar 21, 2024
0.1.0 Mar 21, 2024

#2 in #boxing

Download history 202/week @ 2024-03-19 8/week @ 2024-03-26 16/week @ 2024-04-02

226 downloads per month
Used in eventsys

MIT license

37KB
709 lines

Anything

Rust

This is a work-in-progess project and not for production use.

Thingy: a [..] thing whose name one has forgotten, does not know, or does not wish to mention. [from Oxford Languages]

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 while falling back to boxing the value, if it's too big.

Example

use anything::Thing;
fn main() {
    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");
  }

Licence

This project is licensed under the MIT license.

No runtime deps