From 2e88b6cb82badd1c4e5e957b2a295e93d8cab0ba Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 4 Dec 2020 23:24:20 +0900 Subject: [PATCH 1/3] Convert Rust Edition to 2018 --- Cargo.toml | 3 ++- src/intervals.rs | 10 +++++----- src/job.rs | 6 +++--- src/lib.rs | 8 ++++---- src/scheduler.rs | 4 ++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1abd334..42d7d31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,10 @@ repository = "https://github.com/mdsherry/clokwerk" keywords = ["scheduler", "job"] categories = ["date-and-time"] license = "Apache-2.0" +edition = "2018" [dependencies] chrono = "0.4" [dev-dependencies] -once_cell = "1.2" \ No newline at end of file +once_cell = "1.2" diff --git a/src/intervals.rs b/src/intervals.rs index 41d7957..c9c8bb3 100644 --- a/src/intervals.rs +++ b/src/intervals.rs @@ -137,7 +137,7 @@ fn day_of_week(i: Interval) -> usize { } } -use Interval::*; +use crate::Interval::*; impl NextTime for Interval { fn next(&self, from: &DateTime) -> DateTime { match *self { @@ -365,10 +365,10 @@ impl TimeUnits for u32 { #[cfg(test)] mod tests { use chrono::prelude::*; - use intervals::NextTime; - use Interval::*; - use RunConfig; - use TimeUnits; + use crate::intervals::NextTime; + use crate::Interval::*; + use crate::RunConfig; + use crate::TimeUnits; #[test] fn basic_units() { diff --git a/src/job.rs b/src/job.rs index ffbeb33..3aada2c 100644 --- a/src/job.rs +++ b/src/job.rs @@ -2,11 +2,11 @@ use crate::{ timeprovider::{ChronoTimeProvider, TimeProvider}, intervals::parse_time, }; use chrono::prelude::*; -use intervals::NextTime; +use crate::intervals::NextTime; use std::fmt::{self, Debug}; use std::marker::PhantomData; -use Interval; -use RunConfig; +use crate::Interval; +use crate::RunConfig; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum RunCount { diff --git a/src/lib.rs b/src/lib.rs index 9028c37..a40e767 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ mod job; mod scheduler; pub mod timeprovider; -use intervals::RunConfig; -pub use intervals::{Interval, NextTime, TimeUnits}; -pub use job::Job; -pub use scheduler::{ScheduleHandle, Scheduler}; +use crate::intervals::RunConfig; +pub use crate::intervals::{Interval, NextTime, TimeUnits}; +pub use crate::job::Job; +pub use crate::scheduler::{ScheduleHandle, Scheduler}; diff --git a/src/scheduler.rs b/src/scheduler.rs index da3ca87..847c51c 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -6,8 +6,8 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread; use std::time::Duration; -use Interval; -use Job; +use crate::Interval; +use crate::Job; /// Job scheduler #[derive(Debug)] pub struct Scheduler From 0c6bd2eb1a309581ac4bb4f08e2858ecbc1e369a Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 4 Dec 2020 23:25:04 +0900 Subject: [PATCH 2/3] Apply rustfmt --- src/intervals.rs | 2 +- src/job.rs | 15 +++++++-------- src/scheduler.rs | 8 +++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/intervals.rs b/src/intervals.rs index c9c8bb3..56d545f 100644 --- a/src/intervals.rs +++ b/src/intervals.rs @@ -364,11 +364,11 @@ impl TimeUnits for u32 { #[cfg(test)] mod tests { - use chrono::prelude::*; use crate::intervals::NextTime; use crate::Interval::*; use crate::RunConfig; use crate::TimeUnits; + use chrono::prelude::*; #[test] fn basic_units() { diff --git a/src/job.rs b/src/job.rs index 3aada2c..5968a07 100644 --- a/src/job.rs +++ b/src/job.rs @@ -1,12 +1,13 @@ +use crate::intervals::NextTime; +use crate::Interval; +use crate::RunConfig; use crate::{ - timeprovider::{ChronoTimeProvider, TimeProvider}, intervals::parse_time, + intervals::parse_time, + timeprovider::{ChronoTimeProvider, TimeProvider}, }; use chrono::prelude::*; -use crate::intervals::NextTime; use std::fmt::{self, Debug}; use std::marker::PhantomData; -use crate::Interval; -use crate::RunConfig; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum RunCount { @@ -95,8 +96,7 @@ where /// If the value comes from an untrusted source, e.g. user input, [`Job::try_at`] will return a result instead. /// /// This method is mutually exclusive with [`Job::plus()`]. - pub fn at(&mut self, time: &str) -> &mut Self - { + pub fn at(&mut self, time: &str) -> &mut Self { self.try_at(time) .expect("Could not convert value into a time") } @@ -113,8 +113,7 @@ where /// ``` /// Times can be specified with or without seconds, and in either 24-hour or 12-hour time. /// Mutually exclusive with [`Job::plus()`]. - pub fn try_at(&mut self, time: &str) -> Result<&mut Self, chrono::ParseError> - { + pub fn try_at(&mut self, time: &str) -> Result<&mut Self, chrono::ParseError> { Ok(self.at_time(parse_time(time)?)) } diff --git a/src/scheduler.rs b/src/scheduler.rs index 847c51c..93d09b4 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -1,4 +1,6 @@ use crate::timeprovider::{ChronoTimeProvider, TimeProvider}; +use crate::Interval; +use crate::Job; use std::default::Default; use std::marker::PhantomData; use std::sync::atomic::AtomicBool; @@ -6,8 +8,6 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread; use std::time::Duration; -use crate::Interval; -use crate::Job; /// Job scheduler #[derive(Debug)] pub struct Scheduler @@ -158,9 +158,7 @@ impl Drop for ScheduleHandle { mod tests { use super::{Scheduler, TimeProvider}; use crate::intervals::*; - use std::{ - sync::{atomic::AtomicU32, atomic::Ordering, Arc}, - }; + use std::sync::{atomic::AtomicU32, atomic::Ordering, Arc}; macro_rules! make_time_provider { ($name:ident : $($time:literal),+) => { From d1f969b7ca18e4e017ce960e28e2096392df8b1a Mon Sep 17 00:00:00 2001 From: tottoto Date: Fri, 4 Dec 2020 23:26:41 +0900 Subject: [PATCH 3/3] Remove unnecessary extern crate statement --- src/job.rs | 10 ---------- src/lib.rs | 2 -- src/scheduler.rs | 2 -- 3 files changed, 14 deletions(-) diff --git a/src/job.rs b/src/job.rs index 5968a07..b471452 100644 --- a/src/job.rs +++ b/src/job.rs @@ -81,8 +81,6 @@ where /// Specify the time of day when a task should run, e.g. /// ```rust - /// # extern crate clokwerk; - /// # extern crate chrono; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// # use chrono::NaiveTime; @@ -103,8 +101,6 @@ where /// Identical to [`Job::at`] except that it returns a Result instead of panicking if the conversion failed. /// ```rust - /// # extern crate clokwerk; - /// # extern crate chrono; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// let mut scheduler = Scheduler::new(); @@ -120,8 +116,6 @@ where /// Similar to [`Job::at`], but it takes a chrono::NaiveTime instead of a `&str`. /// Because it doesn't need to parse a string, this method will always succeed. /// ```rust - /// # extern crate clokwerk; - /// # extern crate chrono; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// # use chrono::NaiveTime; @@ -138,7 +132,6 @@ where } /// Add additional precision time to when a task should run, e.g. /// ```rust - /// # extern crate clokwerk; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// let mut scheduler = Scheduler::new(); @@ -191,7 +184,6 @@ where /// After running once, run again with the specified interval. /// /// ```rust - /// # extern crate clokwerk; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// # fn hit_snooze() {} @@ -207,7 +199,6 @@ where /// Unlike [`Job::at`] and [`Job::plus`], /// this affects all intervals associated with the job, not just the most recent one. /// ```rust - /// # extern crate clokwerk; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// # fn hit_snooze() {} @@ -226,7 +217,6 @@ where /// /// If a job is still repeating, it will ignore otherwise scheduled runs. /// ```rust - /// # extern crate clokwerk; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// # fn hit_snooze() {} diff --git a/src/lib.rs b/src/lib.rs index a40e767..d73e3f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,8 +46,6 @@ //! //! ## Similar libraries //! * [schedule-rs](https://github.com/mehcode/schedule-rs) and [job_scheduler](https://github.com/lholden/job_scheduler) are two other Rust scheduler libraries. Both use `cron` syntax for scheduling. -extern crate chrono; - mod intervals; mod job; mod scheduler; diff --git a/src/scheduler.rs b/src/scheduler.rs index 93d09b4..69fb22a 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -66,7 +66,6 @@ where { /// Add a new job to the scheduler to be run on the given interval /// ```rust - /// # extern crate clokwerk; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// let mut scheduler = Scheduler::new(); @@ -88,7 +87,6 @@ where /// other tasks from running as scheduled. If you have a long-running task, you might consider /// having the job move the work into another thread so that it can return promptly. /// ```rust - /// # extern crate clokwerk; /// # use clokwerk::*; /// # use clokwerk::Interval::*; /// use std::thread;