bit_byte_bit/
operators.rs

1use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, Shl, ShlAssign, Shr, ShrAssign};
2use crate::Bits;
3
4impl BitAnd for Bits {
5    type Output = Self;
6
7    /// Bitwise and of two bit strings.
8    ///
9    /// # Examples
10    /// ```
11    /// # use bit_byte_bit::{Bits};
12    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
13    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
14    ///
15    /// assert_eq!(x1 & y1, Bits::new([0x20, 0x30, 0x40]));
16    ///
17    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
18    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
19    ///
20    /// assert_eq!(x2.len(), 23);
21    /// assert_eq!(y2.len(), 24);
22    ///
23    /// let z = x2 & y2;
24    ///
25    /// assert_eq!(z.len(), 24);
26    /// ```
27    fn bitand(self, rhs: Self) -> Self::Output { self.and(&rhs) }
28}
29
30impl BitAnd<&Bits> for Bits {
31    type Output = Bits;
32
33    /// Bitwise and of two bit strings.
34    ///
35    /// # Examples
36    /// ```
37    /// # use bit_byte_bit::{Bits};
38    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
39    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
40    ///
41    /// assert_eq!(x1 & &y1, Bits::new([0x20, 0x30, 0x40]));
42    ///
43    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
44    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
45    ///
46    /// assert_eq!(x2.len(), 23);
47    /// assert_eq!(y2.len(), 24);
48    ///
49    /// let z = x2 & &y2;
50    ///
51    /// assert_eq!(z.len(), 24);
52    /// ```
53    fn bitand(self, rhs: &Bits) -> Self::Output { self.and(rhs) }
54}
55
56impl<'a> BitAnd<Bits> for &'a Bits {
57    type Output = Bits;
58
59    /// Bitwise and of two bit strings.
60    ///
61    /// # Examples
62    /// ```
63    /// # use bit_byte_bit::{Bits};
64    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
65    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
66    ///
67    /// assert_eq!(&x1 & y1, Bits::new([0x20, 0x30, 0x40]));
68    ///
69    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
70    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
71    ///
72    /// assert_eq!(x2.len(), 23);
73    /// assert_eq!(y2.len(), 24);
74    ///
75    /// let z = &x2 & y2;
76    ///
77    /// assert_eq!(z.len(), 24);
78    /// ```
79    fn bitand(self, rhs: Bits) -> Self::Output { self.and(&rhs) }
80}
81
82impl BitAnd<&Bits> for &Bits {
83    type Output = Bits;
84
85    /// Bitwise and of two bit strings.
86    ///
87    /// # Examples
88    /// ```
89    /// # use bit_byte_bit::{Bits};
90    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
91    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
92    ///
93    /// assert_eq!(x1 & &y1, Bits::new([0x20, 0x30, 0x40]));
94    ///
95    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
96    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
97    ///
98    /// assert_eq!(x2.len(), 23);
99    /// assert_eq!(y2.len(), 24);
100    ///
101    /// let z = x2 & &y2;
102    ///
103    /// assert_eq!(z.len(), 24);
104    /// ```
105    fn bitand(self, rhs: &Bits) -> Self::Output { self.and(rhs) }
106}
107
108impl BitAndAssign for Bits {
109    /// Bitwise and of two bit strings.
110    ///
111    /// # Examples
112    /// ```
113    /// # use bit_byte_bit::{Bits};
114    /// let mut x1 = Bits::from([0x20, 0x30, 0x40]);
115    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
116    ///
117    /// x1 &= y1;
118    ///
119    /// assert_eq!(x1, Bits::new([0x20, 0x30, 0x40]));
120    ///
121    /// let mut x2 = Bits::from([0x20, 0x30, 0x40]);
122    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
123    ///
124    /// assert_eq!(x2.len(), 23);
125    /// assert_eq!(y2.len(), 24);
126    ///
127    /// x2 &= y2;
128    ///
129    /// assert_eq!(x2.len(), 24);
130    /// ```
131    fn bitand_assign(&mut self, rhs: Self) { self.and_mut(&rhs); }
132}
133
134impl BitAndAssign<&Bits> for Bits {
135    /// Bitwise and of two bit strings.
136    ///
137    /// # Examples
138    /// ```
139    /// # use bit_byte_bit::{Bits};
140    /// let mut x1 = Bits::from([0x20, 0x30, 0x40]);
141    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
142    ///
143    /// x1 &= &y1;
144    ///
145    /// assert_eq!(x1, Bits::new([0x20, 0x30, 0x40]));
146    ///
147    /// let mut x2 = Bits::from([0x20, 0x30, 0x40]);
148    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
149    ///
150    /// assert_eq!(x2.len(), 23);
151    /// assert_eq!(y2.len(), 24);
152    ///
153    /// x2 &= &y2;
154    ///
155    /// assert_eq!(x2.len(), 24);
156    /// ```
157    fn bitand_assign(&mut self, rhs: &Bits) { self.and_mut(rhs); }
158}
159
160impl BitOr for Bits {
161    type Output = Self;
162
163    /// Bitwise or of two bit strings.
164    ///
165    /// # Examples
166    /// ```
167    /// # use bit_byte_bit::{Bits};
168    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
169    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
170    ///
171    /// assert_eq!(x1 | y1, Bits::from([0xA0, 0xB0, 0xC0]));
172    ///
173    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
174    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
175    ///
176    /// assert_eq!(x2.len(), 23);
177    /// assert_eq!(y2.len(), 24);
178    ///
179    /// let z = x2 | y2;
180    ///
181    /// assert_eq!(z.len(), 24);
182    /// ```
183    fn bitor(self, rhs: Self) -> Self::Output { self.or(&rhs) }
184}
185
186impl BitOr<&Bits> for Bits {
187    type Output = Bits;
188
189    /// Bitwise or of two bit strings.
190    ///
191    /// # Examples
192    /// ```
193    /// # use bit_byte_bit::{Bits};
194    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
195    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
196    ///
197    /// assert_eq!(x1 | &y1, Bits::from([0xA0, 0xB0, 0xC0]));
198    ///
199    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
200    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
201    ///
202    /// assert_eq!(x2.len(), 23);
203    /// assert_eq!(y2.len(), 24);
204    ///
205    /// let z = x2 | &y2;
206    ///
207    /// assert_eq!(z.len(), 24);
208    /// ```
209    fn bitor(self, rhs: &Bits) -> Self::Output { self.or(rhs) }
210}
211
212impl<'a> BitOr<Bits> for &'a Bits {
213    type Output = Bits;
214
215    /// Bitwise or of two bit strings.
216    ///
217    /// # Examples
218    /// ```
219    /// # use bit_byte_bit::{Bits};
220    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
221    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
222    ///
223    /// assert_eq!(&x1 | y1, Bits::from([0xA0, 0xB0, 0xC0]));
224    ///
225    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
226    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
227    ///
228    /// assert_eq!(x2.len(), 23);
229    /// assert_eq!(y2.len(), 24);
230    ///
231    /// let z = &x2 | y2;
232    ///
233    /// assert_eq!(z.len(), 24);
234    /// ```
235    fn bitor(self, rhs: Bits) -> Self::Output { self.or(&rhs) }
236}
237
238impl BitOr<&Bits> for &Bits {
239    type Output = Bits;
240
241    /// Bitwise or of two bit strings.
242    ///
243    /// # Examples
244    /// ```
245    /// # use bit_byte_bit::{Bits};
246    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
247    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
248    ///
249    /// assert_eq!(x1 | &y1, Bits::from([0xA0, 0xB0, 0xC0]));
250    ///
251    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
252    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
253    ///
254    /// assert_eq!(x2.len(), 23);
255    /// assert_eq!(y2.len(), 24);
256    ///
257    /// let z = x2 | &y2;
258    ///
259    /// assert_eq!(z.len(), 24);
260    /// ```
261    fn bitor(self, rhs: &Bits) -> Self::Output { self.or(rhs) }
262}
263
264impl BitOrAssign for Bits {
265    /// Bitwise or of two bit strings.
266    ///
267    /// # Examples
268    /// ```
269    /// # use bit_byte_bit::{Bits};
270    /// let mut x1 = Bits::from([0x20, 0x30, 0x40]);
271    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
272    ///
273    /// x1 |= y1;
274    ///
275    /// assert_eq!(x1, Bits::from([0xA0, 0xB0, 0xC0]));
276    ///
277    /// let mut x2 = Bits::from([0x20, 0x30, 0x40]);
278    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
279    ///
280    /// assert_eq!(x2.len(), 23);
281    /// assert_eq!(y2.len(), 24);
282    ///
283    /// x2 |= y2;
284    ///
285    /// assert_eq!(x2.len(), 24);
286    /// ```
287    fn bitor_assign(&mut self, rhs: Self) { self.or_mut(&rhs); }
288}
289
290impl BitOrAssign<&Bits> for Bits {
291    /// Bitwise or of two bit strings.
292    ///
293    /// # Examples
294    /// ```
295    /// # use bit_byte_bit::{Bits};
296    /// let mut x1 = Bits::from([0x20, 0x30, 0x40]);
297    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
298    ///
299    /// x1 |= &y1;
300    ///
301    /// assert_eq!(x1, Bits::from([0xA0, 0xB0, 0xC0]));
302    ///
303    /// let mut x2 = Bits::from([0x20, 0x30, 0x40]);
304    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
305    ///
306    /// assert_eq!(x2.len(), 23);
307    /// assert_eq!(y2.len(), 24);
308    ///
309    /// x2 |= &y2;
310    ///
311    /// assert_eq!(x2.len(), 24);
312    /// ```
313    fn bitor_assign(&mut self, rhs: &Bits) { self.or_mut(rhs); }
314}
315
316impl BitXor for Bits {
317    type Output = Self;
318
319    /// Bitwise exclusive or of two bit strings.
320    ///
321    /// # Examples
322    /// ```
323    /// # use bit_byte_bit::{Bits};
324    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
325    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
326    ///
327    /// assert_eq!(x1 ^ y1, Bits::from([0x80, 0x80, 0x80]));
328    ///
329    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
330    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
331    ///
332    /// assert_eq!(x2.len(), 23);
333    /// assert_eq!(y2.len(), 24);
334    ///
335    /// let z = x2 ^ y2;
336    ///
337    /// assert_eq!(z.len(), 24);
338    /// ```
339    fn bitxor(self, rhs: Self) -> Self::Output { self.xor(&rhs) }
340}
341
342impl BitXor<&Bits> for Bits {
343    type Output = Bits;
344
345    /// Bitwise exclusive or of two bit strings.
346    ///
347    /// # Examples
348    /// ```
349    /// # use bit_byte_bit::{Bits};
350    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
351    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
352    ///
353    /// assert_eq!(x1 ^ &y1, Bits::from([0x80, 0x80, 0x80]));
354    ///
355    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
356    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
357    ///
358    /// assert_eq!(x2.len(), 23);
359    /// assert_eq!(y2.len(), 24);
360    ///
361    /// let z = x2 ^ &y2;
362    ///
363    /// assert_eq!(z.len(), 24);
364    /// ```
365    fn bitxor(self, rhs: &Bits) -> Self::Output { self.xor(rhs) }
366}
367
368impl<'a> BitXor<Bits> for &'a Bits {
369    type Output = Bits;
370
371    /// Bitwise exclusive or of two bit strings.
372    ///
373    /// # Examples
374    /// ```
375    /// # use bit_byte_bit::{Bits};
376    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
377    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
378    ///
379    /// assert_eq!(&x1 ^ y1, Bits::from([0x80, 0x80, 0x80]));
380    ///
381    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
382    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
383    ///
384    /// assert_eq!(x2.len(), 23);
385    /// assert_eq!(y2.len(), 24);
386    ///
387    /// let z = &x2 ^ y2;
388    ///
389    /// assert_eq!(z.len(), 24);
390    /// ```
391    fn bitxor(self, rhs: Bits) -> Self::Output { self.xor(&rhs) }
392}
393
394impl BitXor<&Bits> for &Bits {
395    type Output = Bits;
396
397    /// Bitwise exclusive or of two bit strings.
398    ///
399    /// # Examples
400    /// ```
401    /// # use bit_byte_bit::{Bits};
402    /// let x1 = Bits::from([0x20, 0x30, 0x40]);
403    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
404    ///
405    /// assert_eq!(x1 ^ &y1, Bits::from([0x80, 0x80, 0x80]));
406    ///
407    /// let x2 = Bits::from([0x20, 0x30, 0x40]);
408    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
409    ///
410    /// assert_eq!(x2.len(), 23);
411    /// assert_eq!(y2.len(), 24);
412    ///
413    /// let z = x2 ^ &y2;
414    ///
415    /// assert_eq!(z.len(), 24);
416    /// ```
417    fn bitxor(self, rhs: &Bits) -> Self::Output { self.xor(rhs) }
418}
419
420impl BitXorAssign for Bits {
421    /// Bitwise exclusive or of two bit strings.
422    ///
423    /// # Examples
424    /// ```
425    /// # use bit_byte_bit::{Bits};
426    /// let mut x1 = Bits::from([0x20, 0x30, 0x40]);
427    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
428    ///
429    /// x1 ^= y1;
430    ///
431    /// assert_eq!(x1, Bits::from([0x80, 0x80, 0x80]));
432    ///
433    /// let mut x2 = Bits::from([0x20, 0x30, 0x40]);
434    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
435    ///
436    /// assert_eq!(x2.len(), 23);
437    /// assert_eq!(y2.len(), 24);
438    ///
439    /// x2 ^= y2;
440    ///
441    /// assert_eq!(x2.len(), 24);
442    /// ```
443    fn bitxor_assign(&mut self, rhs: Self) { self.xor_mut(&rhs); }
444}
445
446impl BitXorAssign<&Bits> for Bits {
447    /// Bitwise exclusive or of two bit strings.
448    ///
449    /// # Examples
450    /// ```
451    /// # use bit_byte_bit::{Bits};
452    /// let mut x1 = Bits::from([0x20, 0x30, 0x40]);
453    /// let y1 = Bits::from([0xA0, 0xB0, 0xC0]);
454    ///
455    /// x1 ^= &y1;
456    ///
457    /// assert_eq!(x1, Bits::from([0x80, 0x80, 0x80]));
458    ///
459    /// let mut x2 = Bits::from([0x20, 0x30, 0x40]);
460    /// let y2 = Bits::from([0x0A, 0xB0, 0xC0]);
461    ///
462    /// assert_eq!(x2.len(), 23);
463    /// assert_eq!(y2.len(), 24);
464    ///
465    /// x2 ^= &y2;
466    ///
467    /// assert_eq!(x2.len(), 24);
468    /// ```
469    fn bitxor_assign(&mut self, rhs: &Bits) { self.xor_mut(&rhs); }
470}
471
472impl Not for Bits {
473    type Output = Self;
474
475    /// Flips every bit.
476    ///
477    /// # Examples
478    /// ```
479    /// # use bit_byte_bit::{Bits};
480    /// let x = Bits::from([0x0A, 0x0B, 0x0C]);
481    ///
482    /// assert_eq!(!x, Bits::slice(&[0xF5, 0xF4, 0x03], 20));
483    /// ```
484    fn not(self) -> Self::Output { self.complement() }
485}
486
487impl Not for &Bits {
488    type Output = Bits;
489
490    /// Flips every bit.
491    ///
492    /// # Examples
493    /// ```
494    /// # use bit_byte_bit::{Bits};
495    /// let x = Bits::from([0x0A, 0x0B, 0x0C]);
496    ///
497    /// assert_eq!(!&x, Bits::slice(&[0xF5, 0xF4, 0x03], 20));
498    /// ```
499    fn not(self) -> Self::Output { self.complement() }
500}
501
502impl Shl<usize> for Bits {
503    type Output = Self;
504
505    /// Shifts out upper bits, shifting in zeros on the lower end.
506    ///
507    /// # Examples
508    /// ```
509    /// # use bit_byte_bit::{Bits};
510    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
511    /// let s1 = x1 << 17;
512    ///
513    /// assert_eq!(s1, Bits::slice(&[0x00, 0x00, 0x04], 20));
514    /// assert_eq!(s1.len(), 20);
515    ///
516    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
517    /// let s2 = x2 << 4;
518    ///
519    /// assert_eq!(s2, Bits::new([0xA0, 0xB0, 0xC0]));
520    /// assert_eq!(s2.len(), 24);
521    /// ```
522    fn shl(self, count: usize) -> Self::Output { self.shifted_left(count) }
523}
524
525impl Shl<usize> for &Bits {
526    type Output = Bits;
527
528    /// Shifts out upper bits, shifting in zeros on the lower end.
529    ///
530    /// # Examples
531    /// ```
532    /// # use bit_byte_bit::{Bits};
533    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
534    /// let s1 = &x1 << 17;
535    ///
536    /// assert_eq!(s1, Bits::slice(&[0x00, 0x00, 0x04], 20));
537    /// assert_eq!(s1.len(), x1.len());
538    ///
539    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
540    /// let s2 = &x2 << 4;
541    ///
542    /// assert_eq!(s2, Bits::new([0xA0, 0xB0, 0xC0]));
543    /// assert_eq!(s2.len(), x2.len());
544    /// ```
545    fn shl(self, count: usize) -> Self::Output { self.shifted_left(count) }
546}
547
548impl Shl<&usize> for Bits {
549    type Output = Self;
550
551    /// Shifts out upper bits, shifting in zeros on the lower end.
552    ///
553    /// # Examples
554    /// ```
555    /// # use bit_byte_bit::{Bits};
556    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
557    /// let s1 = x1 << &17;
558    ///
559    /// assert_eq!(s1, Bits::slice(&[0x00, 0x00, 0x04], 20));
560    /// assert_eq!(s1.len(), 20);
561    ///
562    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
563    /// let s2 = x2 << &4;
564    ///
565    /// assert_eq!(s2, Bits::new([0xA0, 0xB0, 0xC0]));
566    /// assert_eq!(s2.len(), 24);
567    /// ```
568    fn shl(self, count: &usize) -> Self::Output { self.shifted_left(*count) }
569}
570
571impl Shl<&usize> for &Bits {
572    type Output = Bits;
573
574    /// Shifts out upper bits, shifting in zeros on the lower end.
575    ///
576    /// # Examples
577    /// ```
578    /// # use bit_byte_bit::{Bits};
579    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
580    /// let s1 = &x1 << &17;
581    ///
582    /// assert_eq!(s1, Bits::slice(&[0x00, 0x00, 0x04], 20));
583    /// assert_eq!(s1.len(), x1.len());
584    ///
585    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
586    /// let s2 = &x2 << &4;
587    ///
588    /// assert_eq!(s2, Bits::new([0xA0, 0xB0, 0xC0]));
589    /// assert_eq!(s2.len(), x2.len());
590    /// ```
591    fn shl(self, count: &usize) -> Self::Output { self.shifted_left(*count) }
592}
593
594impl ShlAssign<usize> for Bits {
595    /// Shifts out upper bits, shifting in zeros on the lower end.
596    ///
597    /// # Examples
598    /// ```
599    /// # use bit_byte_bit::{Bits};
600    /// let mut x1 = Bits::from([0x0A, 0x0B, 0x0C]);
601    ///
602    /// x1 <<= 17;
603    ///
604    /// assert_eq!(x1, Bits::slice(&[0x00, 0x00, 0x04], 20));
605    /// assert_eq!(x1.len(), 20);
606    ///
607    /// let mut x2 = Bits::new([0x0A, 0x0B, 0x0C]);
608    ///
609    /// x2 <<= 4;
610    ///
611    /// assert_eq!(x2, Bits::new([0xA0, 0xB0, 0xC0]));
612    /// assert_eq!(x2.len(), 24);
613    /// ```
614    fn shl_assign(&mut self, count: usize) { self.shift_left(count); }
615}
616
617impl ShlAssign<&usize> for Bits {
618    /// Shifts out upper bits, shifting in zeros on the lower end.
619    ///
620    /// # Examples
621    /// ```
622    /// # use bit_byte_bit::{Bits};
623    /// let mut x1 = Bits::from([0x0A, 0x0B, 0x0C]);
624    ///
625    /// x1 <<= &17;
626    ///
627    /// assert_eq!(x1, Bits::slice(&[0x00, 0x00, 0x04], 20));
628    /// assert_eq!(x1.len(), 20);
629    ///
630    /// let mut x2 = Bits::new([0x0A, 0x0B, 0x0C]);
631    ///
632    /// x2 <<= &4;
633    ///
634    /// assert_eq!(x2, Bits::new([0xA0, 0xB0, 0xC0]));
635    /// assert_eq!(x2.len(), 24);
636    /// ```
637    fn shl_assign(&mut self, count: &usize) { self.shift_left(*count); }
638}
639
640impl Shr<usize> for Bits {
641    type Output = Self;
642
643    /// Shifts out lower bits, shifting zeros into the upper bits.
644    ///
645    /// # Examples
646    /// ```
647    /// # use bit_byte_bit::{Bits};
648    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
649    /// let s1 = x1 >> 17;
650    ///
651    /// assert_eq!(s1.len(), 20);
652    /// assert_eq!(s1, Bits::slice(&[0x06, 0x00, 0x00], 20));
653    ///
654    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
655    /// let s2 = x2 >> 4;
656    ///
657    /// assert_eq!(s2.len(), 24);
658    /// assert_eq!(s2, Bits::new([0xB0, 0xC0, 0x00]));
659    /// ```
660    fn shr(self, count: usize) -> Self::Output { self.shifted_right(count) }
661}
662
663impl Shr<usize> for &Bits {
664    type Output = Bits;
665
666    /// Shifts out lower bits, shifting zeros into the upper bits.
667    ///
668    /// # Examples
669    /// ```
670    /// # use bit_byte_bit::{Bits};
671    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
672    /// let s1 = &x1 >> 17;
673    ///
674    /// assert_eq!(s1.len(), x1.len());
675    /// assert_eq!(s1, Bits::slice(&[0x06, 0x00, 0x00], 20));
676    ///
677    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
678    /// let s2 = &x2 >> 4;
679    ///
680    /// assert_eq!(s2.len(), x2.len());
681    /// assert_eq!(s2, Bits::new([0xB0, 0xC0, 0x00]));
682    /// ```
683    fn shr(self, count: usize) -> Self::Output { self.shifted_right(count) }
684}
685
686impl Shr<&usize> for Bits {
687    type Output = Self;
688
689    /// Shifts out lower bits, shifting zeros into the upper bits.
690    ///
691    /// # Examples
692    /// ```
693    /// # use bit_byte_bit::{Bits};
694    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
695    /// let s1 = x1 >> &17;
696    ///
697    /// assert_eq!(s1.len(), 20);
698    /// assert_eq!(s1, Bits::slice(&[0x06, 0x00, 0x00], 20));
699    ///
700    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
701    /// let s2 = x2 >> &4;
702    ///
703    /// assert_eq!(s2.len(), 24);
704    /// assert_eq!(s2, Bits::new([0xB0, 0xC0, 0x00]));
705    /// ```
706    fn shr(self, count: &usize) -> Self::Output { self.shifted_right(*count) }
707}
708
709impl Shr<&usize> for &Bits {
710    type Output = Bits;
711
712    /// Shifts out lower bits, shifting zeros into the upper bits.
713    ///
714    /// # Examples
715    /// ```
716    /// # use bit_byte_bit::{Bits};
717    /// let x1 = Bits::from([0x0A, 0x0B, 0x0C]);
718    /// let s1 = &x1 >> &17;
719    ///
720    /// assert_eq!(s1.len(), x1.len());
721    /// assert_eq!(s1, Bits::slice(&[0x06, 0x00, 0x00], 20));
722    ///
723    /// let x2 = Bits::new([0x0A, 0x0B, 0x0C]);
724    /// let s2 = &x2 >> &4;
725    ///
726    /// assert_eq!(s2.len(), 24);
727    /// assert_eq!(s2, Bits::new([0xB0, 0xC0, 0x00]));
728    /// ```
729    fn shr(self, count: &usize) -> Self::Output { self.shifted_right(*count) }
730}
731
732impl ShrAssign<usize> for Bits {
733    /// Shifts out lower bits, shifting zeros into the upper bits.
734    ///
735    /// # Examples
736    /// ```
737    /// # use bit_byte_bit::{Bits};
738    /// let mut x1 = Bits::from([0x0A, 0x0B, 0x0C]);
739    ///
740    /// x1 >>= 17;
741    ///
742    /// assert_eq!(x1, Bits::slice(&[0x06, 0x00, 0x00], 20));
743    /// assert_eq!(x1.len(), 20);
744    ///
745    /// let mut x2 = Bits::new([0x0A, 0x0B, 0x0C]);
746    ///
747    /// x2 >>= 4;
748    ///
749    /// assert_eq!(x2, Bits::new([0xB0, 0xC0, 0x00]));
750    /// assert_eq!(x2.len(), 24);
751    /// ```
752    fn shr_assign(&mut self, count: usize) { self.shift_right(count); }
753}
754
755impl ShrAssign<&usize> for Bits {
756    /// Shifts out lower bits, shifting zeros into the upper bits.
757    ///
758    /// # Examples
759    /// ```
760    /// # use bit_byte_bit::{Bits};
761    /// let mut x1 = Bits::from([0x0A, 0x0B, 0x0C]);
762    ///
763    /// x1 >>= &17;
764    ///
765    /// assert_eq!(x1.len(), 20);
766    /// assert_eq!(x1, Bits::slice(&[0x06, 0x00, 0x00], 20));
767    ///
768    /// let mut x2 = Bits::new([0x0A, 0x0B, 0x0C]);
769    ///
770    /// x2 >>= &4;
771    ///
772    /// assert_eq!(x2.len(), 24);
773    /// assert_eq!(x2, Bits::new([0xB0, 0xC0, 0x00]));
774    /// ```
775    fn shr_assign(&mut self, count: &usize) { self.shift_right(*count); }
776}