pub struct StrategyShowEntries {
    reversed_sort: bool,
    sort_strategy: Box<dyn ISortEntries>,
}
Expand description

Represents a way of displaying a list of EntryInformation objects in a particular order. The order of sorting is a strategy that can be specified when the struct is instantiated. The sorting strategy can be modified with a flag indicating whether the sort is reversed from normal (in this case, descending instead of ascending).

In this particular approach, a struct with a specific sorting strategy is instantiated. The instance can be applied to any number of lists to achieve the specified sorting behavior. Note that the sorting behavior cannot be changed once the StrategyShowEntries struct is instantiated.

An alternative implementation would be to pass the choice of sorting strategy to the show_entries() method and instantiate the sorting struct there and the list is sorted and displayed using the specified sorting strategy. The advantage of this approach is that only one instance of the StrategyShowEntries struct is needed. The disadvantage is the need for two additional parameters that must be passed in all the time along with the entries to be sorted (there might be places in the program where the sorting strategy is not known or is unavailable from the user).

Fields§

§reversed_sort: bool

Specify the sort direction (true = Ascending, false = Descending).

§sort_strategy: Box<dyn ISortEntries>

The sorting strategy to use.

Implementations§

source§

impl StrategyShowEntries

source

pub fn new(sort_options: SortOptions, reversed_sort: bool) -> StrategyShowEntries

Constructor.

Parameters
  • sort_option

    A value from the SortOptions enumeration indicating the sorting strategy to use.

  • reversed_sort

    true if to sort in descending order; otherwise, sort in ascending order.

Returns

Returns a new instance of the StrategyShowEntries struct.

source

pub fn show_entries(&self, entries: &Vec<EntryInformation>)

Display the specified entries in sorted order. The sorting strategy and the order of the sort were established when the StrategyShowEntries struct was instantiated.

Parameters
  • entries

    The list of entries to sort and display. The original list is not changed.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

source§

fn vzip(self) -> V