Skip to content

Support custom reprs, and constants in range bounds #8

Open
@Stargateur

Description

@Stargateur

My use case of this crate is as follow:

bounded_integer! {
    #[repr(libc::c_int)]
    pub struct TimeOut { -1..=libc::c_int::MAX }
}

bounded_integer! {
    #[repr(usize)]
    pub struct MaxEvents{ 1..=libc::c_int::MAX as usize }
}

Unfortunately, this can't be parsed by the macro.

For the first one we could have an alternate:

bounded_integer! {
    #[repr(libc::c_int)]
    pub struct TimeOut { -1.. }
}

This one is possible, I guess.

And the second one I could do:

const TMP : usize = libc::c_int::MAX as usize;

bounded_integer! {
    #[repr(usize)]
    pub struct MaxEvents{ 1..=TMP }
}

But I guess it will be hard.

There is also that #[repr(libc::c_int)] is not possible but #[repr(transparent)] should allow that without problem not need to use #[repr(libc::c_int)]directly for structure. I don't think it's possible for enum rust-lang/rust#68122.

This is just a feedback of my personal use case, I totally agree with closing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions