supply 0.1.0

Provider API for arbitrary number of lifetimes.
Documentation

# Supply

Provider API for arbitrary number of lifetimes.

![Version](https://img.shields.io/static/v1?label=version&message=0.1.0&color=informational)
[![docs.rs](https://img.shields.io/docsrs/supply)](https://docs.rs/supply/latest/supply/)
![Version](https://img.shields.io/static/v1?label=MSRV&message=1.79.0&color=informational)
[![Crates.io License](https://img.shields.io/crates/l/supply)](#license)
[![Crates.io](https://img.shields.io/crates/v/supply)](https://crates.io/crates/supply)

[`supply`](crate) implements an API similar to that proposed in
[RFC 3192](https://rust-lang.github.io/rfcs/3192-dyno.html). It allows
accessing data based on type tags. Expanding on RFC 3192, `supply`
allows accessing data with an arbitrary number of lifetimes. Additionally,
`supply` allows for multiple values to be requested at once.

``` rust
use supply::{Provider, ProviderDyn, Want, LtList, Lt1, tag::AddLt, RequestExt as _};

struct Person<'a> {
    name: &'a str,
    age: u8,
}

// Implementing Provider allows requesting data from a Person value.
impl<'a> Provider for Person<'a> {
    type Lifetimes = Lt1<'a>;

    fn provide<'r>(&'r self, want: &mut dyn Want<'r, Lt1<'a>>) {
        // Provide the name and age fields.
        want.provide_tag::<AddLt<&AddLt<str>>>(self.name)
            .provide_value(self.age);
    }
}

// Make an example person to request data from.
let name = String::from("bob");

let provided_name;
{
    let person = Person {
        name: &name,
        age: 42,
    };

    // Convert to a trait object to show Provider is object safe.
    let provider: &dyn ProviderDyn<Lt1> = &person;

    // Request the person's name.
    provided_name = <AddLt<&AddLt<str>>>::request(provider);
    assert_eq!(provided_name, Some("bob"));

    // Request the person's age.
    let provided_age = u8::request(provider);
    assert_eq!(provided_age, Some(42));

    // Request something Person doesn't provide.
    // We just don't get a value from the request.
    let provided_something = f32::request(provider);
    assert_eq!(provided_something, None);
};

// Because the name was tagged as &'a str we can still access it here.
assert_eq!(provided_name, Some("bob"));
```

### `no_std` Support

This crate is `#![no_std]` by default, it can be used anywhere Rust can.

### Minimum Supported Rust Version

Requires Rust 1.79.0.

This crate follows the ["Latest stable Rust" policy](https://gist.github.com/alexheretic/d1e98d8433b602e57f5d0a9637927e0c). The listed MSRV won't be changed unless needed.
However, updating the MSRV anywhere up to the latest stable at time of release
is allowed.

## Contributing

Contributions in any form (issues, pull requests, etc.) to this project must adhere to 
Rust's [Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct).

Unless you explicitly state otherwise, any contribution intentionally submitted for 
inclusion in `supply` by you shall be licensed as below, without any 
additional terms or conditions.

## License

This project is licensed under either of

  * [Apache License 2.0]LICENSE-Apache-2.0
  * [MIT License]LICENSE-MIT

at your option.