Remembear is a Rust library which can be built as a binary application. This guide will get you up to speed on how to contribute
-
Install Rust, then install
clippyandrustfmtfor lintingrustup component add clippy rustup component add rustfmt -
Install Sqlite3 for the database
brew install sqlite # macOS apt-get install sqlite # Ubuntu/Mint/others -
Clone remembear
git clone git@github.com:codehearts/remembear.git cd remembear -
Make sure you can lint and test the project. This will also install Git hooks
cargo clippy --all-features cargo fmt --all -- --check cargo test -
Now all that's left is to run remembear locally!
cargo run
If you're new to Rust, you may find these resources helpful:
- Rust Website
See the Rust Book (big read), Rust by Example (much more skimmable), and Rustlings (quick hands-on learning) - Rust Playground
Lets you run Rust in your browser like a scratchpad - Rust Community
You can always reach out to me (@codehearts), but the larger Rust community is also available on forums and via chat
This project uses a data provider model, with most modules being organized into these three files:
error.rs- Error types specific to the modulemodel.rs- Models, usually structs, for representing the module's dataprovider.rs- Utilizes dependencies like the database to provide model data
The overall project structure is as follows:
src/- Source codelib.rs- Library entrypointmain.rs- Binary entrypointcommand/- Command-line interface moduledatabase/- Database integrationintegration/- Integrations with external servicesreminder/- Reminder datatypesschedule/- Stateless schedule datatypeprovider/- Provides schedule data from the databasemodel/- Models for serialized schedule data
scheduler/- Real-time reminder scheduleruser/- User datatypes
tests/- Integration testsassets/- Integration test assetscommon/- Common integration test functionalitycommon_database/- Common functionality for integration tests that need a database
migrations/- Database schemas for use with Dieseldiesel.toml- Configurations for Dieselremembear.yml- Default configuration file for remembear
Remembear is written with the latest stable version of Rust and makes extensive use of these crates:
- Diesel for persistent storage with sqlite3
Integration with external services can be added with support for local storage.
- Create a directory for your integration in
src/integration/ - Implement the
Integrationtrait
nameshould return a name for your integrationexecuteis where you can implement a CLI interface for your integrationnotifyis called when a scheduled reminder goes off. This is where you'll integrate with the external service and do something with the reminder.
- Initialize your integration in
Integrations::new() - Last but not least, enable your integration in
remembear.yml!
You can look at src/integration/console/ for an example which writes to stdout, with support for setting colors for assignees in the database via a CLI interface.
Code changes should be unit tested whenever possible. Place your tests in a tests module at the bottom of the file and annotate your test functions with #[test]. Tests will have access to private functions and should have a descriptive name beginning with it_ (my preference, nbd!)
Note that order doesn't matter in assertions, Rust uses "left/right" instead of "expected/actual"
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_adds_2_and_2_to_4() {
assert_eq!(4, 2 + 2);
}
}Run unit tests with Cargo:
cargo test # test everything
cargo test it_adds # tests all functions matching "it_adds"Code changes that impact connectivity between modules or which can't be unit tested should have integration tests. These tests go in tests/ and should have a descriptive rustdoc at the top. If a test is resource intensive or slow, be sure to annotate it with #[ignored]
//! Integration tests for adding two numbers ¯\_(ツ)_/¯
#[test]
#[ignored]
fn it_adds_2_and_2_to_4() {
assert_eq!(4, 2 + 2);
}Integration tests are run the same as unit tests, but tests annotated with #[ignored] must be run like so:
cargo test -- --ignored # test everything
cargo test it_adds -- --ignored # tests ignored functions matching "it_adds"Once your code is polished and tests are passing, it's time to submit a pull request! When the CI build for your branch passes and a project owner reviews your code (which should happen within a few days), your change will be rebased into the master branch and your contribution complete! Nice work! 💖
For features or bugs, you can create a new issue in the tracker
For questions or concerns, feel free to reach out to @codehearts on Twitter or by email!