array_tool::vec

Trait Uniq

Source
pub trait Uniq<T> {
    // Required methods
    fn uniq(&self, other: Self) -> Self;
    fn unique(&self) -> Self;
    fn is_unique(&self) -> bool;
    fn uniq_via<F: Fn(&T, &T) -> bool>(&self, other: Self, f: F) -> Self;
    fn unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> Self;
    fn is_unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> bool;
}
Expand description

Several different methods for getting, or evaluating, uniqueness.

Required Methods§

Source

fn uniq(&self, other: Self) -> Self

uniq returns a vector of unique values within itself as compared to the other vector which is provided as an input parameter.

§Example
use array_tool::vec::Uniq;

vec![1,2,3,4,5,6].uniq( vec![1,2,5,7,9] );
§Output
vec![3,4,6]
Source

fn unique(&self) -> Self

unique removes duplicates from within the vector and returns Self.

§Example
use array_tool::vec::Uniq;

vec![1,2,1,3,2,3,4,5,6].unique();
§Output
vec![1,2,3,4,5,6]
Source

fn is_unique(&self) -> bool

is_unique returns boolean value on whether all values within Self are unique.

§Example
use array_tool::vec::Uniq;

vec![1,2,1,3,4,3,4,5,6].is_unique();
§Output
false
Source

fn uniq_via<F: Fn(&T, &T) -> bool>(&self, other: Self, f: F) -> Self

uniq_via returns a vector of unique values within itself as compared to the other vector which is provided as an input parameter, as defined by a provided custom comparator.

§Example
use array_tool::vec::Uniq;

vec![1,2,3,4,5,6].uniq_via( vec![1,2,5,7,9], |&l, r| l == r + 2 );
§Output
vec![1,2,4,6]
Source

fn unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> Self

unique_via removes duplicates, as defined by a provided custom comparator, from within the vector and returns Self.

§Example
use array_tool::vec::Uniq;

vec![1.0,2.0,1.4,3.3,2.1,3.5,4.6,5.2,6.2].unique_via( |l: &f64, r: &f64| l.floor() == r.floor() );
§Output
vec![1.0,2.0,3.3,4.6,5.2,6.2]
Source

fn is_unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> bool

is_unique_via returns boolean value on whether all values within Self are unique, as defined by a provided custom comparator.

§Example
use array_tool::vec::Uniq;

vec![1.0,2.0,1.4,3.3,2.1,3.5,4.6,5.2,6.2].is_unique_via( |l: &f64, r: &f64| l.floor() == r.floor() );
§Output
false

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Clone + PartialEq> Uniq<T> for Vec<T>

Source§

fn uniq(&self, other: Vec<T>) -> Vec<T>

Source§

fn unique(&self) -> Vec<T>

Source§

fn is_unique(&self) -> bool

Source§

fn uniq_via<F: Fn(&T, &T) -> bool>(&self, other: Vec<T>, f: F) -> Vec<T>

Source§

fn unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> Vec<T>

Source§

fn is_unique_via<F: Fn(&T, &T) -> bool>(&self, f: F) -> bool

Implementors§