portaldi 0.4.0

An ergonomic lightweight compile-time depencency injection library.
Documentation
# PortalDI

PortalDI is a ergonomic, lightweight and compile-time dependency injection (DI) library for Rust.

<div align="left">
  <!-- Crates version -->
  <a href="https://crates.io/crates/portaldi">
    <img src="https://img.shields.io/crates/v/portaldi.svg?style=flat-square"
    alt="Crates.io version" />
  </a>
  <!-- docs -->
  <a href="https://docs.rs/portaldi">
    <img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
      alt="docs.rs docs" />
  </a>
  <!-- CI -->
  <a href="https://github.com/mtn81/portaldi/actions">
    <img src="https://github.com/mtn81/portaldi/actions/workflows/ci-for-main.yml/badge.svg"
      alt="CI status" />
  </a>
</div>
	

### Features
* Ergonomic apis for DI.

  You can forcus on a target type in most cases without worrying about containers.

  ```rust
  Hoge::di().hello(); 
  ```

* Natively async support.
  
  * Asynchronous component creation is enabled.

  ```rust
  AsyncHoge::di()
  .await
  .hello()
  ```

* DRY support by proc-macros.

  Almost boiler codes can be generated by PortalDI's proc-macro.

  ```rust
  #[derive(DIPortal)]
  struct Hoge {
    foo: DI<Foo>,
    ...
  }
  ```

* Wasm support.
  
  * In Wasm target, PortalDI compiles DI container as Rc compatible.

  * In non Wasm target, components and traits must be `thread-safe` (`Sync + Send`).




### Example
```rust
use portaldi::*;

#[derive(DIPortal)]
struct Hoge {
    foo: DI<dyn FooI>,
    bar: DI<Bar>,
}
impl Hoge {
    fn say_hello(&self) {
        println!("hello hoge < {}, {}", self.foo.hello(), self.bar.hello())
    }
}

pub trait FooI: DITarget {
    fn hello(&self) -> &str;
}

#[derive(DIPortal)]
#[provide(FooI)]
struct Foo {}

impl FooI for Foo {
    fn hello(&self) -> &str {
        "hello foo"
    }
}

#[derive(DIPortal)]
struct Bar {}

impl Bar {
    fn hello(&self) -> &str {
        "hello bar"
    }
}

fn main() {
    Hoge::di().say_hello();
}


```

### Guides

For detailed guides, see [docs page](https://docs.rs/portaldi/latest/portaldi/docs/index.html)

#### License

Licensed under either of [Apache License, Version
2.0](LICENSE-APACHE) or [MIT license](LICENSE-MIT) at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this project by you, as defined in the Apache-2.0 license,
shall be dual licensed as above, without any additional terms or conditions.