Skip to content

Allow deriving Zeroable with explicitly provided bounds #190

@wdanilo

Description

@wdanilo

Hi, I've got a code like this:

#[derive(Debug, Derivative, Zeroable)]
#[derivative(Default(bound = "T: Default"))]
pub struct LinkedCellArray<T, const N: usize = 32> {
    size:          Cell<usize>,
    first_segment: ZeroableOption<Box<Segment<T, N>>>,
}

And deriving Zeroable adds T: Zeroable bound. This is bad, as I've got impl<T> Zeroable for ZeroableOption<T> {} for any T implemented. Doing manual impl<T, N> Zeroable for LinkedCellArray<T, const N> {} is also bad, as it does not check the soundness when the code is changed. Would it be possible to add an option to Zeroable to provide a custom bound, something like the following? :)

#[derive(Debug, Derivative, Zeroable)]
#[derivative(Default(bound = "T: Default"))]
#[zeroable(bound = "")]
pub struct LinkedCellArray<T, const N: usize = 32> {
    size:          Cell<usize>,
    first_segment: ZeroableOption<Box<Segment<T, N>>>,
}

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