supply 0.2.0

Provider API for arbitrary number of lifetimes.
Documentation
use std::fmt::Debug;

use supply::prelude::*;

#[cfg(feature = "std")]
#[test]
fn example_1() {
    // Source: https://doc.rust-lang.org/std/any/index.html#smart-pointers-and-dyn-any

    let boxed: Box<dyn Anything> = Box::new(3_i32);

    let actual_id = (*boxed).tag_id();
    let boxed_id = boxed.tag_id();

    assert_eq!(actual_id, TagTypeId::of::<i32>());
    assert_eq!(boxed_id, TagTypeId::<l![]>::of::<Box<dyn Anything>>());
}

#[cfg(feature = "std")]
#[test]
fn example_2() {
    // Source: https://doc.rust-lang.org/std/any/index.html#examples

    fn log<T: Anything + Debug>(value: &T) -> String {
        let value_any = value as &dyn Anything;
        match value_any.downcast_ref::<String>() {
            Some(as_string) => {
                format!("String ({}): {}", as_string.len(), as_string)
            }
            None => {
                format!("{value:?}")
            }
        }
    }

    fn do_work<T: Anything + Debug>(value: &T) -> String {
        log(value)
    }

    let my_string = "Hello World".to_string();
    let x = do_work(&my_string);
    assert_eq!(x, "String (11): Hello World");

    let my_i8: i8 = 100;
    let x = do_work(&my_i8);
    assert_eq!(x, "100");
}

#[test]
fn example_3() {
    assert!(<() as AnythingExt>::is::<()>(&()));
    assert!(<str as AnythingExt>::is::<str>("test"));
}

#[test]
fn any_static() {
    struct A {
        name: String,
    }

    let a = A {
        name: String::from("bob"),
    };

    let x: &dyn Anything = AnyStatic::from_ref(&a);
    let y = x.downcast_ref::<AnyStatic<A>>();
    assert_eq!(y.unwrap().name, "bob");
}