Skip to content

Commit a906c77

Browse files
committed
Add Copy to CopyAs
1 parent 635f738 commit a906c77

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ pub mod common {
280280
///
281281
/// We use this trait to unify the ability of `T` and `&T` to be converted into `T`.
282282
/// This is handy for copy types that we'd like to use, like `u8`, `u64` and `usize`.
283-
pub trait CopyAs<T> {
283+
pub trait CopyAs<T> : Copy {
284284
fn copy_as(self) -> T;
285285
}
286286
impl<T: Copy> CopyAs<T> for &T {
287287
#[inline(always)] fn copy_as(self) -> T { *self }
288288
}
289-
impl<T> CopyAs<T> for T {
289+
impl<T: Copy> CopyAs<T> for T {
290290
#[inline(always)] fn copy_as(self) -> T { self }
291291
}
292292

@@ -1143,7 +1143,7 @@ pub mod primitive {
11431143
}
11441144
}
11451145

1146-
impl<const K: u64, CC: CopyAs<u64> + Copy> Len for Fixeds<K, CC> {
1146+
impl<const K: u64, CC: CopyAs<u64>> Len for Fixeds<K, CC> {
11471147
#[inline(always)] fn len(&self) -> usize { self.count.copy_as() as usize }
11481148
}
11491149

@@ -1191,7 +1191,7 @@ pub mod primitive {
11911191
}
11921192

11931193
use super::Strides;
1194-
impl<const K: u64, BC: Len, CC: CopyAs<u64>+Copy> std::convert::TryFrom<Strides<BC, CC>> for Fixeds<K, CC> {
1194+
impl<const K: u64, BC: Len, CC: CopyAs<u64>> std::convert::TryFrom<Strides<BC, CC>> for Fixeds<K, CC> {
11951195
// On error we return the original.
11961196
type Error = Strides<BC, CC>;
11971197
fn try_from(item: Strides<BC, CC>) -> Result<Self, Self::Error> {
@@ -1243,7 +1243,7 @@ pub mod primitive {
12431243
impl Push<u64> for Strides { #[inline(always)] fn push(&mut self, item: u64) { self.push(item) } }
12441244
impl Clear for Strides { #[inline(always)] fn clear(&mut self) { self.clear() } }
12451245

1246-
impl<BC: Len, CC: CopyAs<u64> + Copy> Len for Strides<BC, CC> {
1246+
impl<BC: Len, CC: CopyAs<u64>> Len for Strides<BC, CC> {
12471247
#[inline(always)]
12481248
fn len(&self) -> usize { self.length.copy_as() as usize + self.bounds.len() }
12491249
}
@@ -1303,7 +1303,7 @@ pub mod primitive {
13031303
}
13041304
}
13051305

1306-
impl<BC: Deref<Target=[u64]>, CC: CopyAs<u64>+Copy> Strides<BC, CC> {
1306+
impl<BC: Deref<Target=[u64]>, CC: CopyAs<u64>> Strides<BC, CC> {
13071307
#[inline(always)]
13081308
pub fn bounds(&self, index: usize) -> (usize, usize) {
13091309
let stride = self.stride.copy_as();
@@ -1317,7 +1317,7 @@ pub mod primitive {
13171317
(lower, upper)
13181318
}
13191319
}
1320-
impl<BC: Len, CC: CopyAs<u64>+Copy> Strides<BC, CC> {
1320+
impl<BC: Len, CC: CopyAs<u64>> Strides<BC, CC> {
13211321
#[inline(always)] pub fn strided(&self) -> Option<u64> {
13221322
if self.bounds.is_empty() {
13231323
Some(self.stride.copy_as())
@@ -1396,7 +1396,7 @@ pub mod primitive {
13961396
}
13971397
}
13981398

1399-
impl<CC: CopyAs<u64> + Copy> Len for Empties<CC> {
1399+
impl<CC: CopyAs<u64>> Len for Empties<CC> {
14001400
#[inline(always)] fn len(&self) -> usize { self.count.copy_as() as usize }
14011401
}
14021402
impl<CC> IndexMut for Empties<CC> {
@@ -1525,11 +1525,11 @@ pub mod primitive {
15251525
}
15261526
}
15271527

1528-
impl<VC: Len, WC: Copy + CopyAs<u64>> Len for Bools<VC, WC> {
1528+
impl<VC: Len, WC: CopyAs<u64>> Len for Bools<VC, WC> {
15291529
#[inline(always)] fn len(&self) -> usize { self.values.len() * 64 + (self.last_bits.copy_as() as usize) }
15301530
}
15311531

1532-
impl<VC: Len + IndexAs<u64>, WC: Copy + CopyAs<u64>> Index for Bools<VC, WC> {
1532+
impl<VC: Len + IndexAs<u64>, WC: CopyAs<u64>> Index for Bools<VC, WC> {
15331533
type Ref = bool;
15341534
#[inline(always)] fn get(&self, index: usize) -> Self::Ref {
15351535
let block = index / 64;
@@ -1543,7 +1543,7 @@ pub mod primitive {
15431543
}
15441544
}
15451545

1546-
impl<VC: Len + IndexAs<u64>, WC: Copy + CopyAs<u64>> Index for &Bools<VC, WC> {
1546+
impl<VC: Len + IndexAs<u64>, WC: CopyAs<u64>> Index for &Bools<VC, WC> {
15471547
type Ref = bool;
15481548
#[inline(always)] fn get(&self, index: usize) -> Self::Ref {
15491549
(*self).get(index)
@@ -2328,13 +2328,13 @@ pub mod sums {
23282328
}
23292329

23302330

2331-
impl<CC, VC: Len + IndexAs<u64>, WC: Copy+CopyAs<u64>> RankSelect<CC, VC, WC> {
2331+
impl<CC, VC: Len + IndexAs<u64>, WC: CopyAs<u64>> RankSelect<CC, VC, WC> {
23322332
#[inline(always)]
23332333
pub fn get(&self, index: usize) -> bool {
23342334
Index::get(&self.values, index)
23352335
}
23362336
}
2337-
impl<CC: Len + IndexAs<u64>, VC: Len + IndexAs<u64>, WC: Copy+CopyAs<u64>> RankSelect<CC, VC, WC> {
2337+
impl<CC: Len + IndexAs<u64>, VC: Len + IndexAs<u64>, WC: CopyAs<u64>> RankSelect<CC, VC, WC> {
23382338
/// The number of set bits *strictly* preceding `index`.
23392339
///
23402340
/// This number is accumulated first by reading out of `self.counts` at the correct position,
@@ -2383,7 +2383,7 @@ pub mod sums {
23832383
}
23842384
}
23852385

2386-
impl<CC, VC: Len, WC: Copy + CopyAs<u64>> RankSelect<CC, VC, WC> {
2386+
impl<CC, VC: Len, WC: CopyAs<u64>> RankSelect<CC, VC, WC> {
23872387
pub fn len(&self) -> usize {
23882388
self.values.len()
23892389
}
@@ -2521,7 +2521,7 @@ pub mod sums {
25212521
}
25222522
}
25232523

2524-
impl<SC, TC, CC, VC: Len, WC: Copy+CopyAs<u64>> Len for Results<SC, TC, CC, VC, WC> {
2524+
impl<SC, TC, CC, VC: Len, WC: CopyAs<u64>> Len for Results<SC, TC, CC, VC, WC> {
25252525
#[inline(always)] fn len(&self) -> usize { self.indexes.len() }
25262526
}
25272527

@@ -2531,7 +2531,7 @@ pub mod sums {
25312531
TC: Index,
25322532
CC: IndexAs<u64> + Len,
25332533
VC: IndexAs<u64> + Len,
2534-
WC: Copy + CopyAs<u64>,
2534+
WC: CopyAs<u64>,
25352535
{
25362536
type Ref = Result<SC::Ref, TC::Ref>;
25372537
#[inline(always)]
@@ -2549,7 +2549,7 @@ pub mod sums {
25492549
&'a TC: Index,
25502550
CC: IndexAs<u64> + Len,
25512551
VC: IndexAs<u64> + Len,
2552-
WC: Copy + CopyAs<u64>,
2552+
WC: CopyAs<u64>,
25532553
{
25542554
type Ref = Result<<&'a SC as Index>::Ref, <&'a TC as Index>::Ref>;
25552555
#[inline(always)]
@@ -2759,11 +2759,11 @@ pub mod sums {
27592759
}
27602760
}
27612761

2762-
impl<T, CC, VC: Len, WC: Copy + CopyAs<u64>> Len for Options<T, CC, VC, WC> {
2762+
impl<T, CC, VC: Len, WC: CopyAs<u64>> Len for Options<T, CC, VC, WC> {
27632763
#[inline(always)] fn len(&self) -> usize { self.indexes.len() }
27642764
}
27652765

2766-
impl<TC: Index, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: Copy+CopyAs<u64>> Index for Options<TC, CC, VC, WC> {
2766+
impl<TC: Index, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: CopyAs<u64>> Index for Options<TC, CC, VC, WC> {
27672767
type Ref = Option<TC::Ref>;
27682768
#[inline(always)]
27692769
fn get(&self, index: usize) -> Self::Ref {
@@ -2774,7 +2774,7 @@ pub mod sums {
27742774
}
27752775
}
27762776
}
2777-
impl<'a, TC, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: Copy+CopyAs<u64>> Index for &'a Options<TC, CC, VC, WC>
2777+
impl<'a, TC, CC: IndexAs<u64> + Len, VC: IndexAs<u64> + Len, WC: CopyAs<u64>> Index for &'a Options<TC, CC, VC, WC>
27782778
where &'a TC: Index
27792779
{
27802780
type Ref = Option<<&'a TC as Index>::Ref>;

0 commit comments

Comments
 (0)