Coverage Report

Created: 2026-02-14 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/crypto-bigint-0.5.5/src/limb/shl.rs
Line
Count
Source
1
//! Limb left bitshift
2
3
use crate::{Limb, Word};
4
use core::ops::{Shl, ShlAssign};
5
6
impl Limb {
7
    /// Computes `self << rhs`.
8
    /// Panics if `rhs` overflows `Limb::BITS`.
9
    #[inline(always)]
10
0
    pub const fn shl(self, rhs: Self) -> Self {
11
0
        Limb(self.0 << rhs.0)
12
0
    }
13
}
14
15
impl Shl for Limb {
16
    type Output = Self;
17
18
    #[inline(always)]
19
0
    fn shl(self, rhs: Self) -> Self::Output {
20
0
        self.shl(rhs)
21
0
    }
22
}
23
24
impl Shl<usize> for Limb {
25
    type Output = Self;
26
27
    #[inline(always)]
28
0
    fn shl(self, rhs: usize) -> Self::Output {
29
0
        self.shl(Limb(rhs as Word))
30
0
    }
31
}
32
33
impl ShlAssign for Limb {
34
    #[inline(always)]
35
0
    fn shl_assign(&mut self, other: Self) {
36
0
        *self = self.shl(other);
37
0
    }
38
}
39
40
impl ShlAssign<usize> for Limb {
41
    #[inline(always)]
42
0
    fn shl_assign(&mut self, other: usize) {
43
0
        *self = self.shl(Limb(other as Word));
44
0
    }
45
}
46
47
#[cfg(test)]
48
mod tests {
49
    use crate::Limb;
50
51
    #[test]
52
    fn shl1() {
53
        assert_eq!(Limb(1) << 1, Limb(2));
54
    }
55
56
    #[test]
57
    fn shl2() {
58
        assert_eq!(Limb(1) << 2, Limb(4));
59
    }
60
61
    #[test]
62
    fn shl_assign1() {
63
        let mut l = Limb(1);
64
        l <<= 1;
65
        assert_eq!(l, Limb(2));
66
    }
67
68
    #[test]
69
    fn shl_assign2() {
70
        let mut l = Limb(1);
71
        l <<= 2;
72
        assert_eq!(l, Limb(4));
73
    }
74
}