jonas-hagen / hx711

A platform agnostic driver to interface with the HX711 (load cell amplifier and ADC)
Apache License 2.0
13 stars 9 forks source link

hx711 incompatible with stable rust #3

Closed twitchyliquid64 closed 4 years ago

twitchyliquid64 commented 4 years ago
error[E0554]: `#![feature]` may not be used on the stable release channel
 --> /home/xxx/.cargo/registry/src/github.com-1ecc6299db9ec823/hx711-0.4.0/src/lib.rs:9:1
  |
9 | #![feature(never_type)]
  | ^^^^^^^^^^^^^^^^^^^^^^^

I'm not super sure what never_type does, is it possible to remove this constraint?

twitchyliquid64 commented 4 years ago

Oh thats what it does :(

error[E0658]: the `!` type is experimental
  --> hx711/src/lib.rs:61:11
   |
61 | impl Into<!> for Error<!, !> {
   |           ^
   |
   = note: see issue #35121 <https://github.com/rust-lang/rust/issues/35121> for more information
jonas-hagen commented 4 years ago

I used the never_type for the .into_ok() usage on operations which cannot fail, e.g. operations which have error type Infallible. See the documentation for a short description. It allows to avoid .unwrap() when one knows it will never fail, and can provide this guarantee at compile time. For example with the stm32fXxx-hal:

# this will never fail, but just from the code this is not obvious
sck_pin.set_high().unwrap()

# here, it is clear that this is always ok
sck_pin.set_high().into_ok()

This requires nightly. When I introduced this, it seemed that never_type is going to stabilize soon. Now it seems rather blocked.

I see that you want to use the driver with stable rust. It is surely possible to remove the usage of never_type. An (optional) never_type feature would be an easy solution. Being compatible with stable rust is probably a wise decision for a platform agnostic driver anyways. Thanks for pointing this out!

jonas-hagen commented 4 years ago

Could you have a look at PR #4 ? This should make this driver usable on stable rust.

twitchyliquid64 commented 4 years ago

Fantastic, that would be perfect!