Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonysy committed Jan 27, 2017
1 parent ee59cca commit 8749249
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hypospray"
description = "Lightweight dependency injection library"
version = "0.1.0"
version = "0.1.1"
authors = ["Jony <[email protected]>"]
keywords = ["dependency-injection", "inversion-of-control", "di"]
readme = "README.md"
Expand Down
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,38 @@

A lightweight dependency injection library

[![License](https://img.shields.io/crates/l/hypospray.svg)](LICENSE)

### Version

```sh
$ rustup -V
rustup 1.0.0 (17b6d21 2016-12-15)
$ rustc -V
rustc 1.16.0-nightly (7821a9b99 2017-01-23)
```
[![](http://meritbadge.herokuapp.com/hypospray)](https://crates.io/crates/hypospray)
[![License](https://img.shields.io/crates/l/hypospray.svg)](#license)

## What is Dependency Injection?

[5-minute introduction.](https://youtu.be/IKD2-MAkXyQ)

## Goals

* Design to allow for focused, reusable, testable components
* Focused, reusable, testable components
* A dependency graph checked at compile time

## Cyclic Dependency

DI is not for circular dependency resolution: [Circular dependency is something that is to be avoided][di post].

## Usage
## Quick-start

### Documentation

* [master](https://docs.rs/hypospray/0.1.0/hypospray/)

### Version Info.

```sh
$ rustup -V
rustup 1.0.0 (17b6d21 2016-12-15)
$ rustc -V
rustc 1.16.0-nightly (7821a9b99 2017-01-23)
```

### Usage

To use `hypospray`, add the following to `Cargo.toml`:

Expand Down
77 changes: 76 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! # Goals
//!
//! * Design to allow for focused, reusable, testable components
//! * Focused, reusable, testable components
//! * A dependency graph checked at compile time
//!
//! # What is Dependency Injection?
Expand All @@ -14,6 +14,81 @@
//! DI is not for circular dependency resolution: [Circular dependency is something that is to be
//! avoided][1].
//!
//! # Example
//!
//! ```rust
//! #![feature(plugin)]
//! #![plugin(hypospray_extensions)]
//! extern crate hypospray;
//!
//! use hypospray::{Co, Construct, Graph};
//!
// work around: https://github.com/rust-lang/cargo/issues/960

//! # fn main() {
//! trait Engine {
//!
//! fn rev(&self) -> &'static str;
//! }
//!
//! #[implements(Engine)]
//! struct GranCabrioV8;
//!
//! impl Engine for GranCabrioV8 {
//!
//! fn rev(&self) -> &'static str {
//!
//! return "Vrooom! Vroom! Vroooom!!!";
//! }
//! }
//!
//! impl<'dep> Construct<'dep> for GranCabrioV8 {
//!
//! type Dep = ();
//!
//! fn __construct(_: Self::Dep) -> GranCabrioV8 {
//! GranCabrioV8
//! }
//! }
//!
//! #[inject(Engine)]
//! trait Deps { }
//!
//! struct SportsCar<M: ?Sized + Deps> { engine: Co<M, Engine> }
//!
//! impl<M: ?Sized + Deps> SportsCar<M> {
//!
//! fn gas(&self) {
//!
//! println!("{}", self.engine.rev());
//! }
//! }
//!
//! impl<'dep, M> Construct<'dep> for SportsCar<M> where M: ?Sized + Deps {
//!
//! type Dep = Co<M, Engine>;
//!
//! fn __construct(engine: Self::Dep) -> SportsCar<M> {
//! SportsCar {
//! engine: engine,
//! }
//! }
//! }
//!
//! #[bind(Engine = "GranCabrioV8#Prototype")]
//! trait Module { }
//!
//! type ModuleDependencies = Graph<Module>;
//!
//! let m = ModuleDependencies::new();
//!
//! let car: SportsCar<_> = m.construct();
//!
//! car.gas();
//! # }
//! ```
//!
//! [1]: http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/
pub use core::{Co, Component, ComponentImp, Construct};
Expand Down

0 comments on commit 8749249

Please sign in to comment.