Struct UsageInformation

Source
pub struct UsageInformation { /* private fields */ }
Expand description

A struct that keeps the records for all tracked objects.

Implementations§

Source§

impl UsageInformation

Source

pub fn add(&mut self, name: &String) -> Result<(), UsageTrackerError>

Adds a new object to keep track of.

§Possible errors
  • UsageTrackerError::ObjectAlreadyTracked
Source

pub fn clear(&mut self)

Removes all objects permanently.

Source

pub fn list(&self) -> Vec<&String>

Provides a vector with all existing keys.

Source

pub fn list_verbose(&self) -> &BTreeMap<String, Usages>

Provides read access to all stored data.

Source

pub fn load_usage_information_from_ron_file<R>( rdr: R, ) -> Result<Self, UsageTrackerError>
where R: Read,

👎Deprecated since 0.2: please only use this function if you have to load files from v0.1

Loads a UsageInformation object from a RON file.

§Explanation

With v0.2, the data layout was changed. To make the transition from v0.1 easier for users, this function was created. It is able to read the RON files produced by v0.1 and convert them into the data structure of v0.2.

§Deprecation

If it still exists by then, v1.0 will see this function removed.

§Possible errors
  • UsageTrackerError::FileLoadErrorRon
Source

pub fn new() -> Self

Creates a new, empty UsageInformation object.

Source

pub fn prune( &mut self, name: &String, before: &Option<DateTime<Utc>>, ) -> Result<(), UsageTrackerError>

Removes usages from an object.

If before is None, all usages are removed. Otherwise, only usages before before are removed.

§Possible errors:
  • UsageTrackerError::ObjectNotTracked
Source

pub fn record_use( &mut self, name: &String, add_if_new: bool, ) -> Result<(), UsageTrackerError>

Records a new usage of an object.

§Possible errors
  • UsageTrackerError::ObjectNotTracked
Source

pub fn remove(&mut self, name: &String)

Removes a currently tracked object permanently.

Source

pub fn usage( &self, name: &String, time_frame: &Duration, ) -> Result<f64, UsageTrackerError>

Calculates the number of usages of the specified object within the specified amount of time.

This works by calculating how much the specified time frame is in comparison to the time since the oldest recorded usage. This relationship is the multiplied by the number of total uses, to calculate a specific number.

§Possible errors
  • UsageTrackerError::ObjectNeverUsed
  • UsageTrackerError::ObjectNotTracked
Source

pub fn usages(&self, name: &String) -> Result<&Usages, UsageTrackerError>

Provides the usages for a specific object.

§Possible errors
  • UsageTrackerError::ObjectNotTracked

Trait Implementations§

Source§

impl Clone for UsageInformation

Source§

fn clone(&self) -> UsageInformation

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UsageInformation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UsageInformation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for UsageInformation

Source§

fn eq(&self, other: &UsageInformation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for UsageInformation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for UsageInformation

Source§

impl StructuralPartialEq for UsageInformation

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,