FlagCounter

Struct FlagCounter 

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

A structure that provides a counter for managing flags or similar use cases.

The FlagCounter struct is designed to keep track of an incrementable count, typically to represent or manage a counter for specific operations or states.

§Fields

  • count:
    • The current value of the counter.
    • Represented as a usize (unsigned integer).

Implementations§

Source§

impl FlagCounter

Source

pub fn new() -> Self

Creates and returns a new instance of the struct with the count field initialized to 0.

§Returns

A new instance of the struct.

Source

pub fn check<T, E>(&mut self, result: Result<T, E>) -> Result<T, E>

Checks the provided Result, increments an internal error count if it is Err, and returns the Result unchanged.

§Type Parameters
  • T: The type of the value inside the Ok variant of the Result.
  • E: The type of the error inside the Err variant of the Result.
§Arguments
  • result: A Result value to be checked for an error.
§Behavior
  • If the provided Result is Err, the method increments the internal error count (self.count).
  • Regardless of whether it is Ok or Err, the original Result is returned unchanged.
§Returns

Returns the provided Result value as-is.

Source

pub fn is_flagged(&self) -> bool

Checks if the current object is flagged.

§Returns
  • true - If the count property of the object is greater than 0.
  • false - If the count property of the object is 0 or less.
§Usage

This function acts as a flagging mechanism. For example, it can be used to determine if there are any active or positive counts that signify certain conditions.

§Note

The count field must be initialized appropriately before calling this function.

Source

pub fn get_count(&self) -> usize

Returns the current value of the count field.

§Returns
  • usize - The value of the count field.

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> 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, 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> ErasedDestructor for T
where T: 'static,