Skip to main content

Schedule

Struct Schedule 

Source
pub struct Schedule<Item: Schedulable> { /* private fields */ }
Expand description

A schedule for managing Schedulable items.

The Schedule structure stores items indexed by their unique identifiers and groups item id by their interval. This allows efficient lookup of items by id and retrieval of all id in a given interval.

OperationTime complexity
GetO(1)
Get dueO(m)
InsertO(1)
RemoveO(1)

m - it’s amount of unique intervals.

Implementations§

Source§

impl<Item: Schedulable> Schedule<Item>

Source

pub fn new() -> Self

Create a new schedule.

Source

pub async fn is_empty(&self) -> bool

Returns true if the Schedule doesn’t contain elements.

Source

pub async fn get(&self, id: Item::Id) -> Option<Arc<Item>>

Get an item by id.

Source

pub async fn get_due(&self, from: i64, to: i64) -> Vec<Arc<Item>>

Get items that are included in the interval from and to.

An element is included in the interval if there is at least one value between from and to that is divisible by the item’s interval without a remainder.

from and to should be > 0 and from should be <= to.

Source

pub async fn insert(&self, item: Item)

Insert an item into schedule.

If an item with this id is already in the schedule, it will be replaced.

Source

pub async fn remove(&self, id: Item::Id)

Remove an item by id from the schedule if it exists.

Source

pub async fn clear(&self)

Clears the schedule, removing all items. Keeps the allocated memory for reuse.

Auto Trait Implementations§

§

impl<Item> !Freeze for Schedule<Item>

§

impl<Item> !RefUnwindSafe for Schedule<Item>

§

impl<Item> Send for Schedule<Item>
where RwLock<HashMap<<Item as Schedulable>::Id, Arc<Item>>>: Send, RwLock<HashMap<<Item as Schedulable>::Interval, HashSet<<Item as Schedulable>::Id>>>: Send,

§

impl<Item> Sync for Schedule<Item>
where RwLock<HashMap<<Item as Schedulable>::Id, Arc<Item>>>: Sync, RwLock<HashMap<<Item as Schedulable>::Interval, HashSet<<Item as Schedulable>::Id>>>: Sync,

§

impl<Item> Unpin for Schedule<Item>
where RwLock<HashMap<<Item as Schedulable>::Id, Arc<Item>>>: Unpin, RwLock<HashMap<<Item as Schedulable>::Interval, HashSet<<Item as Schedulable>::Id>>>: Unpin,

§

impl<Item> UnsafeUnpin for Schedule<Item>
where RwLock<HashMap<<Item as Schedulable>::Id, Arc<Item>>>: UnsafeUnpin, RwLock<HashMap<<Item as Schedulable>::Interval, HashSet<<Item as Schedulable>::Id>>>: UnsafeUnpin,

§

impl<Item> UnwindSafe for Schedule<Item>
where RwLock<HashMap<<Item as Schedulable>::Id, Arc<Item>>>: UnwindSafe, RwLock<HashMap<<Item as Schedulable>::Interval, HashSet<<Item as Schedulable>::Id>>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more