Documentation

anyrust

GitHub license

A library that provides a type system as flexible and powerful as Javascript.

Usage

Usage is simple and intuitive. All you have to do is box the value into the anyrust::Any type and use it appropriately.

Below is a simple example.

use anyrust::*;

fn main() {
    let a = Any::new(5);
    let b = Any::new("10");
    let result = a + b;

    println!("result: {result}"); // result: 510
}

Primitives

The basic integer type, basic float type, boolean type, and string type support mutual conversion with Any without any problem.

Array

Arrays are supported through the anyrust::Array type. This is compatible with Vec<Any>.

    let mut arr = array![1, 2, 3, 4, 5];
    arr.push(4444);
    arr.push("foo");

    for e in arr {
        println!("{e}");
    }

Map

KV Map is supported through the anyrust::Map type. This is compatible with HashMap<Any,Any>.

    let mut map = Any::from(Map::new());
    map.set("name".into(), "John Doe".into());
    map.set("age".into(), 30.into());
    map.set("is_adult".into(), true.into());

    println!("{}", map.to_string());

    for e in map {
        let (k, v) = e.to_pair().to_tuple();

        println!("{}: {}", k, v);
    }