Skip to main content

RullstCollection

Trait RullstCollection 

Source
pub trait RullstCollection<T> {
    // Required methods
    fn key_by<K, F>(self, f: F) -> HashMap<K, T>
       where F: Fn(&T) -> K,
             K: Hash + Eq;
    fn chunk(self, size: usize) -> Vec<Vec<T>>;
    fn implode<F>(&self, separator: &str, f: F) -> String
       where F: Fn(&T) -> String;
    fn sum_by<N, F>(&self, f: F) -> N
       where F: Fn(&T) -> N,
             N: Sum;
    fn max_by_key<K, F>(&self, f: F) -> Option<&T>
       where F: Fn(&T) -> K,
             K: Ord;
    fn min_by_key<K, F>(&self, f: F) -> Option<&T>
       where F: Fn(&T) -> K,
             K: Ord;
    fn collection_resource(&self) -> Value
       where T: ApiResource;
}
Expand description

An extension trait that brings Laravel-style Collection methods natively to Rust’s Vec.

Required Methods§

Source

fn key_by<K, F>(self, f: F) -> HashMap<K, T>
where F: Fn(&T) -> K, K: Hash + Eq,

Keys the collection by the given closure’s return value

Source

fn chunk(self, size: usize) -> Vec<Vec<T>>

Splits the collection into chunks of the given size

Source

fn implode<F>(&self, separator: &str, f: F) -> String
where F: Fn(&T) -> String,

Joins the items into a single string using the given separator and closure

Source

fn sum_by<N, F>(&self, f: F) -> N
where F: Fn(&T) -> N, N: Sum,

Sums up the values returned by the closure

Source

fn max_by_key<K, F>(&self, f: F) -> Option<&T>
where F: Fn(&T) -> K, K: Ord,

Finds the maximum value returned by the closure

Source

fn min_by_key<K, F>(&self, f: F) -> Option<&T>
where F: Fn(&T) -> K, K: Ord,

Finds the minimum value returned by the closure

Source

fn collection_resource(&self) -> Value
where T: ApiResource,

Serializes the entire collection using an ApiResource transformer

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> RullstCollection<T> for Vec<T>

Source§

fn key_by<K, F>(self, f: F) -> HashMap<K, T>
where F: Fn(&T) -> K, K: Hash + Eq,

Source§

fn chunk(self, size: usize) -> Vec<Vec<T>>

Source§

fn implode<F>(&self, separator: &str, f: F) -> String
where F: Fn(&T) -> String,

Source§

fn sum_by<N, F>(&self, f: F) -> N
where F: Fn(&T) -> N, N: Sum,

Source§

fn max_by_key<K, F>(&self, f: F) -> Option<&T>
where F: Fn(&T) -> K, K: Ord,

Source§

fn min_by_key<K, F>(&self, f: F) -> Option<&T>
where F: Fn(&T) -> K, K: Ord,

Source§

fn collection_resource(&self) -> Value
where T: ApiResource,

Implementors§