Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make setters work with basic types #75

Open
kehrazy opened this issue Aug 17, 2023 · 2 comments
Open

make setters work with basic types #75

kehrazy opened this issue Aug 17, 2023 · 2 comments

Comments

@kehrazy
Copy link

kehrazy commented Aug 17, 2023

constructing a new {U}Int<{u/i}{8/16/32/whatever}, ...> each time we need to assign something seems really tedious. In getters we have a .value(), is there an API for us to use in setters?

(edit by maintainer: set_field1(u4::new(2)) vs. set_field1(2))

@hecatia-elegua
Copy link
Owner

I agree it's tedious.

I've had thoughts about

fn set_field1<T: Into<uN>>(value: T) {
    let value: uN = value.into();
    // same stuff as in our current set_field1(value)
}

which would be possible since arbitrary_int provides these conversions (actually it doesn't currently), although we'd special case only arbint fields based on that (which would again be done by looking at the type name, or probably type system magic).
I prototyped this, the result being:
image
meaning you'd write 1u8 here instead of u2::new(1) or 1.into(). Not sure if that's useful enough?

I would not like set_field1_primitive(value: u8), though it would be easier to type with editor help, also not set_field1_(value: u8) to make it shorter. Although set_field1 would not panic, while set_field1_ does.

Arbitrary integers in rust itself would make this easy to write

@kehrazy
Copy link
Author

kehrazy commented Aug 18, 2023

meaning you'd write 1u8 here instead of u2::new(1) or 1.into()

1u8 feels really clear, not gonna lie.

it was always the callee responsibility to pass a proper value to the setter :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants