Skip to content

[Proposal] #exclude_from_comparison attribute #1345

@KalitaAlexey

Description

@KalitaAlexey

Let's consider the struct

struct List {
    name: String,    
    items: RefCell<Vec<Item>>,
}

Let's consider we need to compare two instances of List. We cannot use #[derive] to implement comparison, because RefCell has no impl for comparison. If we want to compare with name field we must manually implement all required traits.
I suggest #[exclude_from_comparison] attribute.
If I had the #[exclude_from_comparison] attribute, then I will write

#[derive(PartialEq)]
#[derive(Eq)]
#[derive(PartialOrd)]
#[derive(Ord)]
struct List {
    name: String,
    #[exclude_from_comparison]
    items: RefCell<Vec<Item>>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions