cc_traits/impls/alloc/
btreeset.rs

1use crate::{
2	Clear, Collection, CollectionMut, CollectionRef, Get, Insert, Iter, Len, Remove,
3	SimpleCollectionMut, SimpleCollectionRef,
4};
5use alloc::collections::BTreeSet;
6use core::borrow::Borrow;
7
8impl<T> Collection for BTreeSet<T> {
9	type Item = T;
10}
11
12impl<T> CollectionRef for BTreeSet<T> {
13	type ItemRef<'a> = &'a T where Self: 'a;
14
15	crate::covariant_item_ref!();
16}
17
18impl<T> CollectionMut for BTreeSet<T> {
19	type ItemMut<'a> = &'a mut T where Self: 'a;
20
21	crate::covariant_item_mut!();
22}
23
24impl<T> SimpleCollectionRef for BTreeSet<T> {
25	crate::simple_collection_ref!();
26}
27
28impl<T> SimpleCollectionMut for BTreeSet<T> {
29	crate::simple_collection_mut!();
30}
31
32impl<T> Len for BTreeSet<T> {
33	#[inline(always)]
34	fn len(&self) -> usize {
35		self.len()
36	}
37
38	#[inline(always)]
39	fn is_empty(&self) -> bool {
40		self.is_empty()
41	}
42}
43
44impl<'a, Q, T: Ord> Get<&'a Q> for BTreeSet<T>
45where
46	T: Borrow<Q>,
47	Q: Ord + ?Sized,
48{
49	#[inline(always)]
50	fn get(&self, t: &'a Q) -> Option<&T> {
51		self.get(t)
52	}
53}
54
55impl<T: Ord> Insert for BTreeSet<T> {
56	type Output = bool;
57
58	#[inline(always)]
59	fn insert(&mut self, t: T) -> bool {
60		self.insert(t)
61	}
62}
63
64impl<'a, Q, T: Ord> Remove<&'a Q> for BTreeSet<T>
65where
66	T: Borrow<Q>,
67	Q: Ord + ?Sized,
68{
69	#[inline(always)]
70	fn remove(&mut self, t: &'a Q) -> Option<T> {
71		self.take(t)
72	}
73}
74
75impl<T: Ord> Clear for BTreeSet<T> {
76	#[inline(always)]
77	fn clear(&mut self) {
78		self.clear()
79	}
80}
81
82impl<T> Iter for BTreeSet<T> {
83	type Iter<'a> = alloc::collections::btree_set::Iter<'a, T> where Self: 'a;
84
85	#[inline(always)]
86	fn iter(&self) -> Self::Iter<'_> {
87		self.iter()
88	}
89}