bradfordboyle / fitbit-grabber-rs

Rust utility for exporting data from Fitbit API
2 stars 3 forks source link

Restructure crate to contain lib and bin #3

Closed anxiousmodernman closed 6 years ago

anxiousmodernman commented 6 years ago

The binary name will be the same. The binary can be built like

cargo build --bin fitbit-grabber

The new library name is "fitbit", and src/bin/main.rs imports it. We could configure to have more binaries, but only one top-level library.

Error handling: Convert errors to failure crate.

On the library side, wrap errors from our dependencies with an enum, and derive Fail for it. This approach to lets us introduce strong types with custom printing fairly quickly. It has the disadvantage of being somewhat rigid, and is one of a few approaches described here: https://boats.gitlab.io/failure/custom-fail.html

On the binary side, as a user of the library, failure allows us to make liberal use of the ? operator, even in main, since main can do Result now.

Config changes, allow a config file: Create application config module

config::Config can be deserialized from a config file at

~/.config/fitbit-grabber/conf.toml

or set with --config at the command line.

The config struct is all Options that must be unwrapped, so we could have separate command funcs that care about particular values on a Config.