#Conflicting implementations of trait when trying to impl on multiple files (multiple mod)

1 messages · Page 1 of 1 (latest)

zinc pine
#

My guess is that #[Object] expands to a trait impl and doesn't support being used more than once

floral cave
#

Wow, this is huge. I'm stucked now.

#

Can you suggest something?

zinc pine
#

If the crate you're using supports this, use that. Check its docs, and ask someone who knows it (so, not me. Maybe #net-and-web?)

Else, if you need to separate the functions, I'm pretty sure the least ugly way to do it looks like this (again, do ask #net-and-web)

//mod.rs
mod coach_resolvers;
mod player_resolvers;

pub struct GamesQuery;
#[Object]
impl GamesQuery {
  coach_resolvers::resolvers!();
  player_resolvers::resolvers!();
}

//coach_resolvers.rs
macro_rules! resolvers {
  () => {
    async fn coach_by_id(&self, ctx: &Context<'_>, id: i64) -> Result<Option<Coach>> {
        // return
    }
  }
}

//player_resolvers.rs
macro_rules! resolvers {
  () => {
    async fn player_by_id(&self, ctx: &Context<'_>, id: i64) -> Result<Option<Coach>> {
        // return
    }
  }
}