dmitryb-dev / waiter Goto Github PK
View Code? Open in Web Editor NEWDependency injection, Inversion of control container for rust with compile time binding.
Dependency injection, Inversion of control container for rust with compile time binding.
I extended the 3_inject_options_list.rs example to implement Interface4 from crate test_def.
use test_def::Interface4;
#[provides]
impl Interface4 for Comp {
fn int4(&self) {
println!("Interface 4");
}
}
I get the following compiling error:
cargo run --color=always --package waiter_di --example 3_inject_options_list
Compiling waiter_di v1.6.4 (/home/steve/workspaces/playground/rust/waiter)
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> examples/3_inject_options_list.rs:116:1
|
116 | #[provides]
| ^^^^^^^^^^^
| |
| impl doesn't use only types from inside the current crate
| `waiter_di::Container` is not defined in the current crate
| `dyn Interface4` is not defined in the current crate
|
= note: define and implement a trait or new type instead
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0117`.
error: could not compile `waiter_di`
I get this error when building my project, where I try to add waiter_ci
in Cargo.toml
:
Compiling waiter_codegen v1.6.4
error[E0432]: unresolved import `syn::export`
--> /home/yves/.cargo/registry/src/github.com-1ecc6299db9ec823/waiter_codegen-1.6.4/src/lib.rs:7:10
|
7 | use syn::export::{TokenStream2, ToTokens};
| ^^^^^^ could not find `export` in `syn`
[× many times…]
error: cannot determine resolution for the macro `quote::quote`
--> /home/yves/.cargo/registry/src/github.com-1ecc6299db9ec823/waiter_codegen-1.6.4/src/component/mod.rs:80:18
|
80 | let result = quote::quote! {
| ^^^^^^^^^^^^
|
= note: import resolution is stuck, try simplifying macro imports
[× many times…]
I'm testing the following async factory function:
struct Dependency {
msg: &'static str
}
impl Dependency {
async fn dep(&self) {
println!("Dep {}", self.msg);
}
}
#[provides]
async fn create_dependency() -> Dependency {
async {
println!("dep factory");
}.await;
Dependency { msg: "Hello, World!" }
}
#[async_std::main]
async fn main() {
let mut container = Container::<profiles::Default>::new();
let comp = Provider::<Dependency>::get_ref(&mut container);
comp.dep().await;
}
I get the following compiling error:
cargo run --color=always --package async_example --bin async_example
Compiling async_example v0.0.1 (/home/steve/workspaces/forks/waiter/crates/async_example)
error[E0308]: mismatched types
--> crates/async_example/src/main.rs:30:1
|
30 | #[provides]
| ^^^^^^^^^^^
| |
| expected struct `Dependency`, found opaque type
| expected `Dependency` because of return type
31 | async fn create_dependency() -> Dependency {
| ---------- the `Output` of this `async fn`'s found opaque type
|
= note: expected struct `Dependency`
found opaque type `impl Future`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: could not compile `async_example`
this works:
#[component]
struct SpecificDuck {}
this does not work:
#[component]
struct SpecificDuck;
the error is:
error[E0618]: expected function, found struct `SpecificDuck`
--> examples/01-waiter-di.rs:11:8
|
10 | #[component]
| ------------ call expression requires function
11 | struct SpecificDuck;
| -------^^^^^^^^^^^^
| |
| struct `SpecificDuck` defined here
|
help: `SpecificDuck` is a unit struct, and does not take parentheses to be constructed
|
10 - #[component]
10 + #[component]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.