SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
7.3k stars 513 forks source link

Why the error `conflicting implementations of trait "std::convert::From<DomainPlayer>" for type "player::ActiveModel"`? #1107

Closed frederikhors closed 2 years ago

frederikhors commented 2 years ago

Let's say I have this code generated with sea-orm-cli:

//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "player")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false, unique)]
    pub id: String,
    pub created_at: TimeDateTimeWithTimeZone,
    #[sea_orm(unique)]
    pub email: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

and this manual struct:

#[derive(Default, Clone)]
pub struct DomainPlayer {
    id: Option<String>,
    created_at: OffsetDateTime,
    email: String,
}

If I try to write this:

impl From<DomainPlayer> for player::ActiveModel {
    fn from(player: DomainPlayer) -> Self {
        Self {
            id: Set(player.id().unwrap()),
            ..Default::default()
        }
    }
}

I get this error:

error[E0119]: conflicting implementations of trait `std::convert::From<domain::player::DomainPlayer>` for type `entities::player::ActiveModel`
    |
133 | impl From<DomainPlayer> for player::ActiveModel {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: conflicting implementation in crate `generated`:
            - impl From<<entities::prelude::Player as EntityTrait>::Model> for entities::player::ActiveModel;

For more information about this error, try `rustc --explain E0119`.

Why?

billy1624 commented 2 years ago

Hey @frederikhors, hi there. This has been discussed before. It's likely some kind of Rust's orphan rule.

Please check related issues / discussions:

billy1624 commented 2 years ago

Let me know if you still have questions on it