Skip to content

conflicting implementations of trait Borrow<std::option::Option<_>> for type Body<_, _> #110532

Open
@MaxKingPor

Description

@MaxKingPor
#[derive(Debug, Default)]
pub struct Body<C, R> {
    content: Option<C>,
    resp: Option<R>,
}

impl<C, R> Deref for Body<C, R> {
    type Target = Option<C>;
    fn deref(&self) -> &Self::Target {
        self.borrow()
    }
}
impl<C, R> DerefMut for Body<C, R> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        self.borrow_mut()
    }
}

impl<C, R> Borrow<Option<C>> for Body<C, R> {
    fn borrow(&self) -> &Option<C> {
        &self.content
    }
}
impl<C, R> BorrowMut<Option<C>> for Body<C, R> {
    fn borrow_mut(&mut self) -> &mut Option<C> {
        &mut self.content
    }
}
impl<C, R> Borrow<Option<R>> for Body<C, R> {
    fn borrow(&self) -> &Option<R> {
        &self.resp
    }
}
impl<C, R> BorrowMut<Option<R>> for Body<C, R> {
    fn borrow_mut(&mut self) -> &mut Option<R> {
        &mut self.resp
    }
}

out

error[E0119]: conflicting implementations of trait `Borrow<std::option::Option<_>>` for type `Body<_, _>`
   --> model/src/customer.rs:117:1
    |
107 | impl<C, R> Borrow<Option<C>> for Body<C, R> {
    | ---------------------------------------------- first implementation here
...
117 | impl<C, R> Borrow<Option<R>> for Body<C, R> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Body<_, _>`

error[E0119]: conflicting implementations of trait `BorrowMut<std::option::Option<_>>` for type `Body<_, _>`
   --> model/src/customer.rs:122:1
    |
112 | impl<C, R> BorrowMut<Option<C>> for Body<C, R> {
    | ------------------------------------------------- first implementation here
...
122 | impl<C, R> BorrowMut<Option<R>> for Body<C, R> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Body<_, _>`

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coherenceArea: CoherenceA-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions