frewsxcv / rust-dark-light

Rust crate to detect if dark mode or light mode is enabled
https://crates.io/crates/dark-light
73 stars 12 forks source link

API needs to be able to report failure to detect, errors #21

Open BartMassey opened 1 year ago

BartMassey commented 1 year ago

Right now if something goes wrong — can't detect mode, error happens during detection attempt — detect() returns Mode::Light. Would be a lot better to provide some version of this that could return a Result.

edfloreshz commented 10 months ago

I believe this is by design, when a failure occurs Mode::Light is taken as the fallback mode.

Adding a Result would over-complicate things in my opinion, as an alternative I would suggest adding an Error variant to the Mode enum.

BartMassey commented 10 months ago

An Error "mode" means that every match against mode will need to handle this case. A Result can be checked for, leaving an actual mode to work with.

If the endpoint uses Result<Mode, Error> one can get the old behavior by

detect().unwrap_or(Mode::Light)

if desired.

edfloreshz commented 10 months ago

@frewsxcv What do you think? I think I brought this up at some point.

frewsxcv commented 8 months ago

Having it return a Result seems reasonable to me