You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0308]: mismatched types
--> src/main.rs:5:10
|
5 | #[derive(Serialize)]
| ^^^^^^^^^ expected `OptionRangedU16<_, _>`, found `&OptionRangedU16<0, 1000>`
6 | struct Struct {
7 | #[serde(skip_serializing_if = "OptionRangedU16::is_none")]
| -------------------------- arguments to this function are incorrect
|
= note: expected struct `OptionRangedU16<_, _>`
found reference `&OptionRangedU16<0, 1000>`
note: method defined here
--> C:\Users\Jacob\scoop\persist\rustup\.cargo\registry\src\index.crates.io-6f17d22bba15001f\deranged-0.3.11\src\lib.rs:1389:1
|
1389 | / impl_ranged! {
1390 | | RangedU8 {
1391 | | mod_name: ranged_u8
1392 | | internal: u8
... |
1473 | | }
1474 | | }
| |_^
= note: this error originates in the derive macro `Serialize` which comes from the expansion of the macro `impl_ranged` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0308`.
I almost certainly assumed it didn't matter because the type is Copy but failed to consider that the function signature itself matters in some contexts.
I can definitely change this. The library isn't widely used (I honestly thought I was one of the only people using it), so having a semver breaking release is essentially a non-issue.
It's a great crate! Reflecting the constraints of a number's range in its type when e.g. designing a library for interacting with an API (e.g. a percent is 0 to 100, a color hue is 0 to 360) brings us self-documentation and validation for free (because you and the other handful of contributors did it for us :) ).
The standard library's
Option
'sis_none
andis_some
take the value by reference.I encountered this when using
serde
:with the full compilation error:
The relevant part of the macro is here:
deranged/src/lib.rs
Lines 958 to 970 in c25ef2c
where changing the
self
parameter to&self
would be trivial, but would be a breaking change.Working around this on my end without a change to this crate is easy enough.
Thanks for your work on
deranged
, it's a great crate!The text was updated successfully, but these errors were encountered: