apasel422 / eclectic Goto Github PK
View Code? Open in Web Editor NEWExperimental collection traits for Rust
Home Page: https://apasel422.github.io/eclectic/eclectic
License: Apache License 2.0
Experimental collection traits for Rust
Home Page: https://apasel422.github.io/eclectic/eclectic
License: Apache License 2.0
Collection
capacity
into_vec
reserve_exact
with_capacity
List
reverse
sort
split_at(_mut)
*Set
{difference, intersection, symmetric_difference, union}
**requires boxed trait objects or higher-kinded associated types
I think it needs HKT or something loopy like that. For instance I tried implementing a super generic "categorize":
extern crate eclectic;
use eclectic::*;
use std::hash::Hash;
pub fn categorize<'a, D, B, F, O, M>(data: D, mut f: F) where
D: IntoIterator + Sized,
B: Default + Extend<D::Item> + 'static,
F: FnMut(&D::Item) -> O,
O: Hash + Eq,
M: EntryMap<Key=O, Value=B> + Default,
{
let map = M::default();
for x in data {
match map.entry(f(&x)) {
Entry::Vacant(v) => v.insert(B::default()),
Entry::Occupied(o) => o.into_mut(),
}.extend(Some(x));
}
map
}
But it's not clear that a lifetime can be supplied for EntryMap.
This would enable node-based collections to directly embed trait objects. For example:
struct Node<T: ?Sized> {
left: Option<Box<Node<T>>>,
right: Option<Box<Node<T>>>,
item: T,
}
pub struct Heap<T: ?Sized> {
root: Option<Box<Node<T>>>,
}
Pending rust-lang/rfcs#1195.
Should it implement List
? Should we add the following method (and/or a corresponding associated type or associated const) to List
?
fn is_random_access(&self) -> bool;
The current design is nonsensical. With some future-Rust features, we could have:
pub trait EntryMap: Map {
type Occupied<'a>: Occupied<'a = 'a, Key = Self::Key, Value = Self::Value>;
type Vacant<'a>: Vacant<'a = 'a, Key = Self::Key, Value = Self::Value>;
fn entry<'a>(&'a mut self, key: Self::Key)
-> Entry<Self::Occupied<'a>, Self::Vacant<'a>>;
}
pub enum Entry<O, V>
where
O: Occupied,
V: Vacant<'a = O::'a, Key = O::Key, Value = O::Value>,
{
Occupied(O),
Vacant(V),
}
pub trait Occupied {
lifetime 'a;
type Key: Self::'a;
type Value: Self::'a;
fn into_mut(self) -> &Self::'a mut Self::Value;
// ...
}
pub trait Vacant {
lifetime 'a;
type Key: Self::'a;
type Value: Self::'a;
fn insert(self, value: Self::Value) -> &Self::'a mut Self::Value;
// ...
}
For example:
list::View<Item = T>
is to list::MutView<Item = T>
is to List<Item = T>
as &[T]
is to &mut [T]
is to Vec<T>
.
It might not be worthwhile to have these as separate traits.
The former doesn't own its keys, and the latter doesn't own its items, but it probably requires higher-kinded types to be able to deal with these in the iteration methods.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.