From 7235281915fee59ad0e7af54b017ef16015349eb Mon Sep 17 00:00:00 2001
From: Lucas Colombo
Date: Mon, 8 Apr 2024 16:44:41 -0300
Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=94=A8=20changed=20feature=20?=
=?UTF-8?q?names?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.github/img/icon-has-submodules.svg | 1 +
.github/img/logo-cli.svg | 11 ++++++++
Cargo.toml | 19 ++++++++-----
README.md | 12 +++++++--
lib/cli/README.md | 24 +++++++++++++++++
lib/cli/mod.rs | 2 +-
lib/cli/stylize/README.md | 4 +--
lib/lib.rs | 1 +
lib/sched/README.md | 41 ++++++++++++++++++++++++-----
lib/sched/rules.rs | 31 +++++++++++++---------
10 files changed, 115 insertions(+), 31 deletions(-)
create mode 100644 .github/img/icon-has-submodules.svg
create mode 100644 .github/img/logo-cli.svg
create mode 100644 lib/cli/README.md
diff --git a/.github/img/icon-has-submodules.svg b/.github/img/icon-has-submodules.svg
new file mode 100644
index 0000000..32b1ea9
--- /dev/null
+++ b/.github/img/icon-has-submodules.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/.github/img/logo-cli.svg b/.github/img/logo-cli.svg
new file mode 100644
index 0000000..2aac400
--- /dev/null
+++ b/.github/img/logo-cli.svg
@@ -0,0 +1,11 @@
+
\ No newline at end of file
diff --git a/Cargo.toml b/Cargo.toml
index 0cbfa65..d8e3655 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,13 +20,18 @@ debug-assertions = false
path = "lib/lib.rs"
[features]
-cli-stylize = ["dep:bitflags"]
-logger = ["dep:log"]
-macros = []
-sched = ["dep:chrono"]
-sched-tokio = ["dep:tokio", "tokio?/time", "tokio?/rt"]
-sched-rule-recurrent = []
-sched-rule-cron = []
+# cli utilities
+"cli" = []
+"cli.stylize" = ["dep:bitflags"]
+# logging
+"logger" = ["dep:log"]
+# macros
+"macros" = []
+# scheduling
+"sched" = ["dep:chrono"]
+"sched.tokio" = ["dep:tokio", "tokio?/time", "tokio?/rt"]
+"sched.rule-recurrence" = []
+"sched.rule-cron" = []
[dependencies]
diff --git a/README.md b/README.md
index 9dd0f0a..8aa83cf 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,15 @@
# Features
-- [x] [cli/stylize](lib/cli/stylize)
+In order to avoid compiling unnecessary code and expensive dependencies, `lool` is split into
+several features and "sub-features".
+
+## Main features
+
+- [x] [cli](lib/cli)
- [x] [logging](lib/logger)
- [x] [macros](lib/macros)
-- [x] [tokio/sched](lib/tokio/sched)
\ No newline at end of file
+- [x] [sched](lib/sched)
+
+> [!NOTE]
+>
: Means that the feature has sub-features.
\ No newline at end of file
diff --git a/lib/cli/README.md b/lib/cli/README.md
new file mode 100644
index 0000000..7b90cd9
--- /dev/null
+++ b/lib/cli/README.md
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+lool » cli contains utilities for building command-line interfaces.
+
+
+
+
+
+
+# Installation
+
+This crate is for internal use. It's only published privately.
+
+```bash
+cargo add lool --registry=lugit --features cli
+```
+
+# Sub-Features
+
+- [x] [`stylize`](./stylize): colorize and stylize text for the terminal.
diff --git a/lib/cli/mod.rs b/lib/cli/mod.rs
index 9168981..07e9900 100644
--- a/lib/cli/mod.rs
+++ b/lib/cli/mod.rs
@@ -1,2 +1,2 @@
-#[cfg(feature = "cli-stylize")]
+#[cfg(feature = "cli.stylize")]
pub mod stylize;
diff --git a/lib/cli/stylize/README.md b/lib/cli/stylize/README.md
index 6c0a072..1a20a7d 100644
--- a/lib/cli/stylize/README.md
+++ b/lib/cli/stylize/README.md
@@ -4,7 +4,7 @@
-lool » cli/stylize is a set of utilities for colorizing console outputs.
+
lool » cli.stylize is a set of utilities for colorizing console outputs.
@@ -16,7 +16,7 @@
This crate is for internal use. It's only published privately.
```bash
-cargo add lool --registry=lugit --features cli-stylize
+cargo add lool --registry=lugit --features cli cli.stylize
```
# Usage
diff --git a/lib/lib.rs b/lib/lib.rs
index b60a4ad..e793ca8 100644
--- a/lib/lib.rs
+++ b/lib/lib.rs
@@ -1,3 +1,4 @@
+#[cfg(feature = "cli")]
pub mod cli;
#[cfg(feature = "sched")]
diff --git a/lib/sched/README.md b/lib/sched/README.md
index 37464ee..1a77516 100644
--- a/lib/sched/README.md
+++ b/lib/sched/README.md
@@ -23,20 +23,49 @@ cargo add lool --registry=lugit --features sched
# Additional Features
-- `sched-tokio`: Enables the `tokio` runtime support.
-- `sched-rule-recurrent`: Enables the "recurrent-rule" style for scheduling tasks.
-- `sched-rule-cron`: Enables the "cron-like" style for scheduling tasks
+- `sched.tokio`: Enables the `tokio` runtime support.
+- `sched.rule-recurrent`: Enables the "recurrent-rule" style for scheduling tasks.
+- `sched.rule-cron`: Enables the "cron-like" style for scheduling tasks
> [!WARNING] Not implemented warning
-> although the `sched-rule-cron` feature is available, it's not yet implemented.
+> although the `sched.rule-cron` feature is available, it's not yet implemented.
## Planned Features
-- `sched-rule-cron`: Enables the "cron-like" style for scheduling tasks
-- `sched-rule-pysched`: Enables the "pysched-like" style for scheduling tasks
+- `sched.rule-cron`: Enables the "cron-like" style for scheduling tasks
+- `sched.rule-pyschedule`: Enables the [python schedule](https://pypi.org/project/schedule/)-like
+ style for scheduling tasks
# Usage
+
+
+# Inspiration
+
+This library is inspired by several other libraries, including:
+
+- [node-schedule](https://github.com/node-schedule/node-schedule?tab=readme-ov-file#recurrence-rule-scheduling):
+ where the idea of recurring rules was taken from.
+- [tokio-schedule](https://github.com/dedefer/tokio_schedule): tokio async scheduler
+- [schedule-rs](https://github.com/mehcode/schedule-rs): simple thread-based scheduler
+- [croner-rust](https://github.com/hexagon/croner-rust): a croner parser for rust
+- [job_scheduler](https://github.com/lholden/job_scheduler): another thread-based job scheduler for
+ rust
+- [python's schedule](https://pypi.org/project/schedule/): a simple python scheduler with
+ a human-friendly API
+
+
+Otros:
+
+- https://crates.io/crates/tokio-cron-scheduler
+- https://crates.io/crates/clokwerk
+- https://crates.io/crates/cron_tab
+- https://crates.io/crates/multithreading
+- https://crates.io/crates/multithreading
+- https://crates.io/crates/threadpool
+- https://crates.io/crates/blocking
+- https://crates.io/crates/scheduled-thread-pool
+- https://crates.io/crates/clokwerk
diff --git a/lib/sched/rules.rs b/lib/sched/rules.rs
index 3e5537e..b1b8c13 100644
--- a/lib/sched/rules.rs
+++ b/lib/sched/rules.rs
@@ -1,8 +1,8 @@
-#[cfg(feature = "sched-rule-cron")]
+#[cfg(feature = "sched.rule-cron")]
mod cron;
-#[cfg(feature = "sched-rule-recurrent")]
+#[cfg(feature = "sched.rule-recurrence")]
mod recurrent;
-#[cfg(feature = "sched-rule-recurrent")]
+#[cfg(feature = "sched.rule-recurrence")]
pub use self::recurrent::{many, range, ranges, ruleset, val, RecurrenceRuleSet, Rule};
use chrono::{DateTime, Local};
@@ -18,11 +18,11 @@ pub enum SchedulingRule {
Once(chrono::DateTime),
/// 🧉 » a scheduling rule expressed with a `RecurrenceRule` structure
- #[cfg(feature = "sched-rule-recurrent")]
+ #[cfg(feature = "sched.rule-recurrence")]
Repeat(RecurrenceRuleSet),
/// 🧉 » a scheduling rule expressed in cron format
- #[cfg(feature = "sched-rule-cron")]
+ #[cfg(feature = "sched.rule-cron")]
Cron(String),
}
@@ -33,17 +33,22 @@ impl SchedulingRule {
}
/// 🧉 » get the next execution time from now
- pub fn next_from(&self, _date: DateTime) -> Option> {
+ pub fn next_from(&self, date: DateTime) -> Option> {
match self {
- SchedulingRule::Once(_dt) => {
- unimplemented!()
+ SchedulingRule::Once(date) => {
+ if date > &date {
+ Some(*date)
+ } else {
+ None
+ }
}
- #[cfg(feature = "sched-rule-recurrent")]
- SchedulingRule::Repeat(_rule) => {
- unimplemented!()
- }
- #[cfg(feature = "sched-rule-cron")]
+
+ #[cfg(feature = "sched.rule-recurrence")]
+ SchedulingRule::Repeat(rule) => rule.next_match_from(date),
+
+ #[cfg(feature = "sched.rule-cron")]
SchedulingRule::Cron(_cron) => {
+ // TODO: implement cron scheduling rule
unimplemented!()
}
}