Skip to content

Suggestion: derive(Len) and derive(IsEmpty) #558

Description

@George-Ogden

Hi
Thanks for making this repo; it's full of great macros!
One thing I write a lot is this:

pub struct MyStruct(Vec<i32>) // or HashSet or BTreeMap

impl MyStruct {
    #[must_use]
    pub const fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    #[must_use]
    pub const fn len(&self) -> usize {
        self.0.len()
    }
    ...
}

I would like it a lot if I could derive this. And it's common enough (for me at least) that I would find a lot of value from it. The #[must_use] and const are just to satisfy clippy, and I think they aren't needed.

What do you think? How difficult would this be to implement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions