Skip to content

[Rust codegen] Incorrectly derives Eq trait for types containing f64 fields #34

@Rhovian

Description

@Rhovian

Problem

When an IDL contains event types with "type": "f64" fields, the generated Rust code fails to compile:

eg;

```rust
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct LendingAccountLiquidateEvent {
    pub liquidatee_pre_health: f64,
    pub liquidatee_post_health: f64,
    ...
}
error[E0277]: the trait bound `f64: std::cmp::Eq` is not satisfied
  --> clients/rust/src/generated/types/lending_account_liquidate_event.rs:30:1

Root Cause

f64 cannot implement Eq because of NaN handling (NaN != NaN). The Rust compiler only allows Eq for types where equality is reflexive, symmetric, and transitive.

Happy to PR a solution to this if no one is working on it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions