Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/ordered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl<S> Ordered<S> {
pub fn try_push<T>(&mut self, element: T) -> Result<(), T>
where
T: PartialOrd,
S: Collection<Item=T> + Back + PushBack // `S` must be a stack providing `back` and `push_back`.
S: Collection<Item=T> + Back + PushBack, // `S` must be a stack providing `back` and `push_back`.
for<'a> S::ItemRef<'a>: PartialOrd<&'a T> // The reference type must be comparable with other reference types.
{
if self.inner.back().map(|back| back <= &element).unwrap_or(true) {
self.inner.push_back(element);
Expand Down
12 changes: 11 additions & 1 deletion src/impls/slab.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use slab::Slab;
use crate::{
Collection,
CollectionRef,
CollectionMut,
WithCapacity,
Len,
Capacity,
Expand All @@ -16,6 +18,14 @@ impl<T> Collection for Slab<T> {
type Item = T;
}

impl<T> CollectionRef for Slab<T> {
type ItemRef<'a> where Self: 'a = &'a T;
}

impl<T> CollectionMut for Slab<T> {
type ItemMut<'a> where Self: 'a = &'a mut T;
}

impl<T> WithCapacity for Slab<T> {
fn with_capacity(capacity: usize) -> Self {
Slab::with_capacity(capacity)
Expand Down Expand Up @@ -53,7 +63,7 @@ impl<T> GetMut<usize> for Slab<T> {
}

impl<T> Insert for Slab<T> {
type Output = usize;
type Output<'a> where Self: 'a = usize;

fn insert(&mut self, element: T) -> usize {
self.insert(element)
Expand Down
12 changes: 11 additions & 1 deletion src/impls/smallvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use smallvec::{
};
use crate::{
Collection,
CollectionRef,
CollectionMut,
WithCapacity,
Len,
Capacity,
Expand All @@ -22,6 +24,14 @@ impl<A: Array> Collection for SmallVec<A> {
type Item = A::Item;
}

impl<A: Array> CollectionRef for SmallVec<A> {
type ItemRef<'a> where Self: 'a = &'a A::Item;
}

impl<A: Array> CollectionMut for SmallVec<A> {
type ItemMut<'a> where Self: 'a = &'a mut A::Item;
}

impl<A: Array> WithCapacity for SmallVec<A> {
#[inline(always)]
fn with_capacity(capacity: usize) -> Self {
Expand Down Expand Up @@ -78,7 +88,7 @@ impl<A: Array> FrontMut for SmallVec<A> {
}

impl<A: Array> PushBack for SmallVec<A> {
type Output = ();
type Output<'a> where Self: 'a = ();

fn push_back(&mut self, t: A::Item) {
self.push(t)
Expand Down
14 changes: 12 additions & 2 deletions src/impls/std_collections/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
};
use crate::{
Collection,
CollectionRef,
CollectionMut,
Len,
Get,
GetMut,
Expand All @@ -16,6 +18,14 @@ impl<K, V> Collection for BTreeMap<K, V> {
type Item = V;
}

impl<K, V> CollectionRef for BTreeMap<K, V> {
type ItemRef<'a> where Self: 'a = &'a V;
}

impl<K, V> CollectionMut for BTreeMap<K, V> {
type ItemMut<'a> where Self: 'a = &'a mut V;
}

impl<K, V> Len for BTreeMap<K, V> {
#[inline(always)]
fn len(&self) -> usize {
Expand All @@ -42,8 +52,8 @@ impl<'a, Q, K: Ord, V> GetMut<&'a Q> for BTreeMap<K, V> where K: Borrow<Q>, Q: O
}
}

impl<'a, K: Ord, V> MapInsert<K> for BTreeMap<K, V> {
type Output = Option<V>;
impl<K: Ord, V> MapInsert<K> for BTreeMap<K, V> {
type Output<'a> where Self: 'a = Option<V>;

#[inline(always)]
fn insert(&mut self, key: K, value: V) -> Option<V> {
Expand Down
14 changes: 12 additions & 2 deletions src/impls/std_collections/btreeset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
};
use crate::{
Collection,
CollectionRef,
CollectionMut,
Len,
Get,
Insert,
Expand All @@ -15,6 +17,14 @@ impl<T> Collection for BTreeSet<T> {
type Item = T;
}

impl<T> CollectionRef for BTreeSet<T> {
type ItemRef<'a> where Self: 'a = &'a T;
}

impl<T> CollectionMut for BTreeSet<T> {
type ItemMut<'a> where Self: 'a = &'a mut T;
}

impl<T> Len for BTreeSet<T> {
#[inline(always)]
fn len(&self) -> usize {
Expand All @@ -34,8 +44,8 @@ impl<'a, Q, T: Ord> Get<&'a Q> for BTreeSet<T> where T: Borrow<Q>, Q: Ord + ?Siz
}
}

impl<'a, T: Ord> Insert for BTreeSet<T> {
type Output = bool;
impl<T: Ord> Insert for BTreeSet<T> {
type Output<'a> where Self: 'a = bool;

#[inline(always)]
fn insert(&mut self, t: T) -> bool {
Expand Down
12 changes: 11 additions & 1 deletion src/impls/std_collections/deque.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::VecDeque;
use crate::{
Collection,
CollectionRef,
CollectionMut,
WithCapacity,
Len,
Capacity,
Expand All @@ -18,6 +20,14 @@ impl<T> Collection for VecDeque<T> {
type Item = T;
}

impl<T> CollectionRef for VecDeque<T> {
type ItemRef<'a> where Self: 'a = &'a T;
}

impl<T> CollectionMut for VecDeque<T> {
type ItemMut<'a> where Self: 'a = &'a mut T;
}

impl<T> WithCapacity for VecDeque<T> {
#[inline(always)]
fn with_capacity(capacity: usize) -> Self {
Expand Down Expand Up @@ -74,7 +84,7 @@ impl<T> FrontMut for VecDeque<T> {
}

impl<T> PushBack for VecDeque<T> {
type Output = ();
type Output<'a> where Self: 'a = ();

fn push_back(&mut self, t: T) {
self.push_back(t)
Expand Down
14 changes: 12 additions & 2 deletions src/impls/std_collections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
};
use crate::{
Collection,
CollectionRef,
CollectionMut,
Len,
Get,
GetMut,
Expand All @@ -17,6 +19,14 @@ impl<K, V> Collection for HashMap<K, V> {
type Item = V;
}

impl<K, V> CollectionRef for HashMap<K, V> {
type ItemRef<'a> where Self: 'a = &'a V;
}

impl<K, V> CollectionMut for HashMap<K, V> {
type ItemMut<'a> where Self: 'a = &'a mut V;
}

impl<K, V> Len for HashMap<K, V> {
#[inline(always)]
fn len(&self) -> usize {
Expand All @@ -43,8 +53,8 @@ impl<'a, Q, K: Hash + Eq, V> GetMut<&'a Q> for HashMap<K, V> where K: Borrow<Q>,
}
}

impl<'a, K: Hash + Eq, V> MapInsert<K> for HashMap<K, V> {
type Output = Option<V>;
impl<K: Hash + Eq, V> MapInsert<K> for HashMap<K, V> {
type Output<'a> where Self: 'a = Option<V>;

#[inline(always)]
fn insert(&mut self, key: K, value: V) -> Option<V> {
Expand Down
14 changes: 12 additions & 2 deletions src/impls/std_collections/hashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
};
use crate::{
Collection,
CollectionRef,
CollectionMut,
Len,
Get,
Insert,
Expand All @@ -16,6 +18,14 @@ impl<T> Collection for HashSet<T> {
type Item = T;
}

impl<T> CollectionRef for HashSet<T> {
type ItemRef<'a> where Self: 'a = &'a T;
}

impl<T> CollectionMut for HashSet<T> {
type ItemMut<'a> where Self: 'a = &'a mut T;
}

impl<T> Len for HashSet<T> {
#[inline(always)]
fn len(&self) -> usize {
Expand All @@ -34,8 +44,8 @@ impl<'a, Q, T: Hash + Eq> Get<&'a Q> for HashSet<T> where T: Borrow<Q>, Q: Hash
}
}

impl<'a, T: Hash + Eq> Insert for HashSet<T> {
type Output = bool;
impl<T: Hash + Eq> Insert for HashSet<T> {
type Output<'a> where Self: 'a = bool;

#[inline(always)]
fn insert(&mut self, t: T) -> bool {
Expand Down
12 changes: 11 additions & 1 deletion src/impls/std_collections/vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
Collection,
CollectionRef,
CollectionMut,
WithCapacity,
Len,
Capacity,
Expand All @@ -18,6 +20,14 @@ impl<T> Collection for Vec<T> {
type Item = T;
}

impl<T> CollectionRef for Vec<T> {
type ItemRef<'a> where Self: 'a = &'a T;
}

impl<T> CollectionMut for Vec<T> {
type ItemMut<'a> where Self: 'a = &'a mut T;
}

impl<T> WithCapacity for Vec<T> {
#[inline(always)]
fn with_capacity(capacity: usize) -> Self {
Expand Down Expand Up @@ -74,7 +84,7 @@ impl<T> FrontMut for Vec<T> {
}

impl<T> PushBack for Vec<T> {
type Output = ();
type Output<'a> where Self: 'a = ();

fn push_back(&mut self, t: T) {
self.push(t)
Expand Down
Loading