Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

 #[router] moves #[data] to the first filter #103

Open
xabufr opened this issue Dec 7, 2021 · 0 comments
Open

 #[router] moves #[data] to the first filter #103

xabufr opened this issue Dec 7, 2021 · 0 comments

Comments

@xabufr
Copy link
Contributor

xabufr commented Dec 7, 2021

When I use the #[router] attribute with multiple services that use #[data] arguments, the generated code doesn't clone #[data].

Example code:

#[router(
    "/tata/",
    services(
        svc1,
        svc2,
        svc3
    )
)]
pub fn my_router(
    #[data] config: AppConfig,
    #[data] mongo: MongoClient,
    #[data] vault: Arc<dyn Vault>,
) {}

Errors:

29 |     #[data] config: AppConfig,
   |             ^^^^^^
   |             |
   |             value moved here
   |             value used here after move

Generated code by cargo expand:

    pub fn my_router(
        config: AppConfig,
        mongo: MongoClient,
        vault: Arc<dyn Vault>,
    ) -> impl Clone + rweb::Filter<Extract = (impl rweb::Reply,), Error = rweb::Rejection> {
        use rweb::{rt::StatusCode, Filter};
        rweb::openapi::with(|__collector: Option<&mut rweb::openapi::Collector>| {
            if let Some(__collector) = __collector {
                __collector.with_appended_prefix("/tata/", ::alloc::vec::Vec::new(), || {
                    rweb::filters::path::path("tata").and(
                        svc1(config, mongo, vault)
                            .or(svc2(config, mongo, vault))
                            .or(svc3(config, mongo, vault)),
                    )
                })
            } else {
                rweb::filters::path::path("tata").and(
                    svc1(config, mongo, vault)
                        .or(svc2(config, mongo, vault))
                        .or(svc3(config, mongo, vault)),
                )
            }
        })
    }

Data arguments should be cloned in methods calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant