From 488faf96336711a527a3610c728a2409087b69fa Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 3 Nov 2022 20:23:49 +0100 Subject: docs: add comments explaining the prevent-circular example --- examples/prevent-circular/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/prevent-circular/main.rs b/examples/prevent-circular/main.rs index 7e10024..c690a9c 100644 --- a/examples/prevent-circular/main.rs +++ b/examples/prevent-circular/main.rs @@ -1,7 +1,10 @@ +//! Example demonstrating the prevention of circular dependencies. +//! +//! Having circular dependencies is generally bad practice and is detected by Syrette when +//! the `prevent-circular` feature is enabled. #![deny(clippy::all)] #![deny(clippy::pedantic)] #![allow(clippy::disallowed_names)] -use std::error::Error; use syrette::di_container::blocking::prelude::*; use syrette::injectable; @@ -9,7 +12,7 @@ use syrette::ptr::TransientPtr; struct Foo { - bar: TransientPtr, + _bar: TransientPtr, } #[injectable] @@ -17,13 +20,13 @@ impl Foo { fn new(bar: TransientPtr) -> Self { - Self { bar } + Self { _bar: bar } } } struct Bar { - foo: TransientPtr, + _foo: TransientPtr, } #[injectable] @@ -31,7 +34,7 @@ impl Bar { fn new(foo: TransientPtr) -> Self { - Self { foo } + Self { _foo: foo } } } @@ -42,7 +45,8 @@ fn main() -> Result<(), anyhow::Error> di_container.bind::().to::()?; di_container.bind::().to::()?; - let foo = di_container.get::()?.transient()?; + // The following won't work. Err will be returned. + let _foo = di_container.get::()?.transient()?; Ok(()) } -- cgit v1.2.3-18-g5258