pub enum ExpansionMode {
    Panic,
    Ignore,
    Overwrite,
    Expand(f64),
}
Expand description

Different modes of action when the FixedSizeCollection is full. Depending on the mode, the collection will behave differently through the check_expansion method.

There are four modes of expansion:

  1. Panic - The collection will panic when the capacity is reached.
  2. Ignore - The collection will ignore the addition of the new item.
  3. Overwrite - The collection will overwrite the an item when the capacity is reached.
  4. Expand - The collection will expand the capacity by a specific factor. The factor must be greater than 1.0. If the factor is 1.0, the function will panic!. This is the default mode with a factor of 2.0.

Examples

Example on how the expansion is checked in FixedSizeCollection through the check_expansion method:

use trait_based_collection::prelude::*;

fn check_expansion<'a, T, C: FixedSizeCollection<'a, T>>(mut collection: C) -> bool {
    if collection.is_full() {
        match collection.mode() {
            ExpansionMode::Panic => {
                panic!("The collection is full");
            }
            ExpansionMode::Ignore => {
                return true;
            }
            ExpansionMode::Overwrite => {
                collection.remove();
            }
            ExpansionMode::Expand(factor) => {
                if *factor < 1.0 {
                    panic!("Expand factor must be greater than 1");
                }
                let size = ((*factor - 1.0) * collection.capacity() as f64).floor() as usize;
                collection.expand(size);
            }
        }
    }
    false
}

Variants

Panic

The collection will panic when the capacity is reached.

Ignore

The collection will ignore the addition of the new item.

Overwrite

The collection will overwrite the an item when the capacity is reached. This means that before the new item is added, an item is removed by calling the remove method.

Expand(f64)

The collection will expand the capacity by a specific factor. The factor must be greater than 1.0. If the factor is 1.0, the function will panic!. This is the default mode with a factor of 2.0.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.