3 releases (breaking)

✓ Uses Rust 2018 edition

0.3.0 Jul 16, 2019
0.1.0 Mar 12, 2019
0.0.1 Mar 8, 2019

#9 in #traits

23 downloads per month

Apache-2.0

14KB
396 lines

Collection Traits (cl-traits)

Yet another library to provide traits that describe 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. That is why this crate provides 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 LengthRet = usize;

  fn length(&self) -> Self::LengthRet {
    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 subdirectories.

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));
}

Future

In the future, given some context and assurance, this crate might provide more complex traits, e.g., ContiguousIndexedSparseCollection.

Dependencies

~175KB