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

Support the #[feign] attribute on trait impls #8

Closed
NightEule5 opened this issue May 21, 2023 · 4 comments
Closed

Support the #[feign] attribute on trait impls #8

NightEule5 opened this issue May 21, 2023 · 4 comments

Comments

@NightEule5
Copy link

NightEule5 commented May 21, 2023

I stumbled onto an unsupported pattern that would be nice to support. I have a trait that can be implemented with get attributes, which works fine:

trait SomeRequest {
    async fn request(&self, id: &str) -> feignhttp::Result<String>;
}

#[derive(Feign)]
struct Struct;

impl SomeRequest for Struct {
    #[get("/some/path/{id}")]
    async fn request(&self, id: &str) -> feignhttp::Result<String> { }
}

But when I add a URL prefix with the feign attribute, it expands to a normal impl without the trait:

#[feign(url = "https://some.url")]
impl SomeRequest for Struct {
    #[get("/some/path/{id}")]
    async fn request(&self, id: &str) -> feignhttp::Result<String> { }
}

// Expands to...

impl Struct {
    async fn request(&self, id: &str) -> feignhttp::Result<String> {
        use feignhttp::FeignClient   as _;
        use std::collections::HashMap;
        use feignhttp::{HttpClient, HttpConfig, HttpResponse, util};
        // ...
    }
}

A workaround is to supply the URL for every request, i.e. #[get(url = "https://some.url", path = "/some/path/{id}")]

@dxx
Copy link
Owner

dxx commented May 27, 2023

Hi!
Traits should not be used to define the method of the request. In the current version of rust, if you define async functions in traits, you must use async-trait crate, but async-trait is conflict with feignhttp.

@NightEule5
Copy link
Author

Async traits work in nightly with the async_fn_in_trait feature enabled

@dxx
Copy link
Owner

dxx commented May 28, 2023

Yes. I have pushed a commit 5c993fd.

@dxx
Copy link
Owner

dxx commented Jun 4, 2023

It is available in 0.5.1 now.

@dxx dxx closed this as completed Sep 9, 2023
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

2 participants