Crates.io | cl-traits-derive |
lib.rs | cl-traits-derive |
version | 1.0.0 |
source | src |
created_at | 2019-03-12 00:50:09.442493 |
updated_at | 2020-04-05 01:26:07.725398 |
description | Derives for cl-traits |
homepage | |
repository | https://github.com/c410-f3r/cl-traits |
max_upload_size | |
id | 120165 |
size | 20,857 |
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.
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 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));
}