Skip to content

Commit

Permalink
Merge pull request #19 from tottoto/update_rust_edition_to_2018
Browse files Browse the repository at this point in the history
Update rust edition to 2018
  • Loading branch information
mdsherry authored Dec 9, 2020
2 parents 8953acf + d1f969b commit 5e9f7b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
once_cell = "1.2"
10 changes: 5 additions & 5 deletions src/intervals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn day_of_week(i: Interval) -> usize {
}
}

use Interval::*;
use crate::Interval::*;
impl NextTime for Interval {
fn next<Tz: TimeZone>(&self, from: &DateTime<Tz>) -> DateTime<Tz> {
match *self {
Expand Down Expand Up @@ -364,11 +364,11 @@ impl TimeUnits for u32 {

#[cfg(test)]
mod tests {
use crate::intervals::NextTime;
use crate::Interval::*;
use crate::RunConfig;
use crate::TimeUnits;
use chrono::prelude::*;
use intervals::NextTime;
use Interval::*;
use RunConfig;
use TimeUnits;

#[test]
fn basic_units() {
Expand Down
25 changes: 7 additions & 18 deletions src/job.rs
Original file line number Diff line number Diff line change
@@ -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 intervals::NextTime;
use std::fmt::{self, Debug};
use std::marker::PhantomData;
use Interval;
use RunConfig;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum RunCount {
Expand Down Expand Up @@ -80,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;
Expand All @@ -95,16 +94,13 @@ 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")
}

/// 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();
Expand All @@ -113,16 +109,13 @@ 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)?))
}

/// 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;
Expand All @@ -139,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();
Expand Down Expand Up @@ -192,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() {}
Expand All @@ -208,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() {}
Expand All @@ -227,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() {}
Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@
//!
//! ## 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;
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};
10 changes: 3 additions & 7 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::timeprovider::{ChronoTimeProvider, TimeProvider};
use crate::Interval;
use crate::Job;
use std::default::Default;
use std::marker::PhantomData;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use Interval;
use Job;
/// Job scheduler
#[derive(Debug)]
pub struct Scheduler<Tz = chrono::Local, Tp = ChronoTimeProvider>
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -168,9 +166,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),+) => {
Expand Down

0 comments on commit 5e9f7b3

Please sign in to comment.