aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-28 11:34:18 +0200
committerHampusM <hampus@hampusmat.com>2022-08-28 11:34:18 +0200
commited2d73ed81da2f6b6784796a1751335c4fa46816 (patch)
tree515768aee1391be99b0c83b7b2f1a87808d9c7e1 /README.md
parent6db30abd6dc915f57192faa5e72d3c3af42cd5b0 (diff)
docs: correct the example in the readme
Diffstat (limited to 'README.md')
-rw-r--r--README.md15
1 files changed, 10 insertions, 5 deletions
diff --git a/README.md b/README.md
index 22db44a..04f2ca4 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,8 @@ The goal of Syrette is to be a simple, useful, convenient and familiar DI librar
## Example usage
```rust
+use std::error::Error;
+
use syrette::{injectable, DIContainer};
use syrette::ptr::TransientPtr;
@@ -70,7 +72,8 @@ trait IWarrior
fn fight(&self);
}
-struct Warrior {
+struct Warrior
+{
weapon: TransientPtr<dyn IWeapon>,
}
@@ -91,19 +94,21 @@ impl IWarrior for Warrior
}
}
-fn main()
+fn main() -> Result<(), Box<dyn Error>>
{
let mut di_container = DIContainer::new();
- di_container.bind::<dyn IWeapon>().to::<Sword>().unwrap();
+ di_container.bind::<dyn IWeapon>().to::<Sword>()?;
- di_container.bind::<dyn IWarrior>().to::<Warrior>().unwrap();
+ di_container.bind::<dyn IWarrior>().to::<Warrior>()?;
- let warrior = di_container.get::<dyn IWarrior>().unwrap();
+ let warrior = di_container.get::<dyn IWarrior>()?.transient()?;
warrior.fight();
println!("Warrior has fighted");
+
+ Ok(())
}
```