5 releases (1 stable)

✓ Uses Rust 2018 edition

1.0.0 Apr 5, 2020
0.4.1 Mar 2, 2020
0.4.0 Mar 2, 2020
0.3.0 Jul 16, 2019
0.0.1 Mar 12, 2019

#302 in Development tools

Download history 5/week @ 2020-01-18 1/week @ 2020-01-25 3/week @ 2020-02-01 6/week @ 2020-02-08 3/week @ 2020-02-15 8/week @ 2020-02-22 34/week @ 2020-02-29 10/week @ 2020-03-07 6/week @ 2020-03-14 21/week @ 2020-03-21 2/week @ 2020-03-28 26/week @ 2020-04-04 35/week @ 2020-04-11 4/week @ 2020-04-18 3/week @ 2020-04-25 4/week @ 2020-05-02

51 downloads per month
Used in cl-traits

Apache-2.0

10KB
218 lines

Collection Traits (cl-traits)

CI crates.io Documentation License Rustc

Yet another library that generalizes collections. This is a best effort without GAT.

Many data structures have unique features that make it difficult or even impossible to create a single trait that fits all. This crate tries to circumvent such behaviour by providing a single method for each trait to achieve maximum flexibility and freedom.

Examples

use cl_traits::*;

struct SomeCustomVector(Vec<i32>, Vec<i32>);

impl Length for SomeCustomVector {
  type Output = usize;

  fn length(&self) -> Self::Output {
    self.0.length() + self.1.length()
  }
}

fn main() {
  let v = SomeCustomVector(vec![1, 2], vec![3, 4, 5, 6]);
  assert_eq!(v.length(), 6);
}

You can see more complete examples in the examples directory.

Derives

Derives are somewhat limited because they aggregate every single attribute, threfore, should be used with caution.

use cl_traits::*;
use cl_traits_derive::*;

#[derive(WithLength)]
struct SomeCustomVector(Vec<i32>, Vec<i32>);

fn main() {
  let v = SomeCustomVector(vec![1, 2], vec![3, 4, 5, 6]);
  assert_eq!(v.length(), (2, 4));
}

Dependencies

~1MB
~28K SLoC