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

generic service traits #10

Open
little-dude opened this issue Mar 26, 2017 · 2 comments
Open

generic service traits #10

little-dude opened this issue Mar 26, 2017 · 2 comments

Comments

@little-dude
Copy link
Contributor

Hi,

I'd like to be able to write something like this:

service! {
    pub trait MyService[T] {
        // [...]
    }
 
   impl for Foo {
        // [...]
    }
    
    impl[U] for U [where U: AsRef<Foo>] {
        // [...]
    }
}

I tried to tweak the service! macro. See little-dude@4fe785a (sorry if I did something horrible here, this is my first time dealing with macros).

I tried it on a simple example (also avalaible on github in case you want to try it):

pub struct Foo<T> {
    phantom: PhantomData<T>,
    adapter: JsonAdapter,
}


service! {
    pub trait MyService[T] {
        fn get_next(&self) -> TryWithRaw<Foo<T>> {
            GET("")
        }
    }

    impl for Foo<T> {
        |this| &this.adapter
    }

    impl[U] for U [where U: AsRef<Foo<T>>] {
        |this| &this.as_ref().adapter
    }
}

The generated code look ok, but I'm hitting that error which I'm not sure how to solve:

error[E0277]: the trait bound `anterofit::net::response::TryWithRaw<Foo<T>>: anterofit::net::FromResponse` is not satisfied
  --> src/lib.rs:14:1
   |
14 | service! {
   | ^ the trait `anterofit::net::FromResponse` is not implemented for `anterofit::net::response::TryWithRaw<Foo<T>>`
   |
   = help: the following implementations were found:
             <anterofit::net::response::TryWithRaw<T> as anterofit::net::FromResponse>
   = note: this error originates in a macro outside of the current crate

I don't really understand because FromResponse is implemented for TryWithRaw<T>, so it should also work for TryWithRaw<Foo<T>> no?

@abonander
Copy link
Owner

I've been working in a better solution for generics on the parse-generics branch, it's coming along okay so far. It shouldn't be too hard to extend it to generics on traits.

@little-dude
Copy link
Contributor Author

You're awesome, I'll take a look 👍

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