Trait elliptic_curve::ops::Shr
1.0.0 · source · pub trait Shr<Rhs = Self> {
type Output;
// Required method
fn shr(self, rhs: Rhs) -> Self::Output;
}
arithmetic
only.Expand description
The right shift operator >>
. Note that because this trait is implemented
for all integer types with multiple right-hand-side types, Rust’s type
checker has special handling for _ >> _
, setting the result type for
integer operations to the type of the left-hand-side operand. This means
that though a >> b
and a.shr(b)
are one and the same from an evaluation
standpoint, they are different when it comes to type inference.
Examples
An implementation of Shr
that lifts the >>
operation on integers to a
wrapper around usize
.
use std::ops::Shr;
#[derive(PartialEq, Debug)]
struct Scalar(usize);
impl Shr<Scalar> for Scalar {
type Output = Self;
fn shr(self, Self(rhs): Self) -> Self::Output {
let Self(lhs) = self;
Self(lhs >> rhs)
}
}
assert_eq!(Scalar(16) >> Scalar(2), Scalar(4));
An implementation of Shr
that spins a vector rightward by a given amount.
use std::ops::Shr;
#[derive(PartialEq, Debug)]
struct SpinVector<T: Clone> {
vec: Vec<T>,
}
impl<T: Clone> Shr<usize> for SpinVector<T> {
type Output = Self;
fn shr(self, rhs: usize) -> Self::Output {
// Rotate the vector by `rhs` places.
let (a, b) = self.vec.split_at(self.vec.len() - rhs);
let mut spun_vector = vec![];
spun_vector.extend_from_slice(b);
spun_vector.extend_from_slice(a);
Self { vec: spun_vector }
}
}
assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } >> 2,
SpinVector { vec: vec![3, 4, 0, 1, 2] });
Required Associated Types§
Required Methods§
Implementors§
source§impl<'lhs, 'rhs, T, const LANES: usize> Shr<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES>where
T: SimdElement,
Simd<T, LANES>: Shr<Output = Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
impl<'lhs, 'rhs, T, const LANES: usize> Shr<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES>where T: SimdElement, Simd<T, LANES>: Shr<Output = Simd<T, LANES>>, LaneCount<LANES>: SupportedLaneCount,
source§impl<T, const LANES: usize> Shr<&Simd<T, LANES>> for Simd<T, LANES>where
T: SimdElement,
Simd<T, LANES>: Shr<Output = Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> Shr<&Simd<T, LANES>> for Simd<T, LANES>where T: SimdElement, Simd<T, LANES>: Shr<Output = Simd<T, LANES>>, LaneCount<LANES>: SupportedLaneCount,
source§impl<T, const LANES: usize> Shr<Simd<T, LANES>> for &Simd<T, LANES>where
T: SimdElement,
Simd<T, LANES>: Shr<Output = Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> Shr<Simd<T, LANES>> for &Simd<T, LANES>where T: SimdElement, Simd<T, LANES>: Shr<Output = Simd<T, LANES>>, LaneCount<LANES>: SupportedLaneCount,
source§impl<U> Shr<U> for UTermwhere
U: Unsigned,
impl<U> Shr<U> for UTermwhere U: Unsigned,
Shifting right a UTerm
by an unsigned integer: UTerm >> U = UTerm
source§impl<U, B> Shr<B0> for UInt<U, B>where
U: Unsigned,
B: Bit,
impl<U, B> Shr<B0> for UInt<U, B>where U: Unsigned, B: Bit,
Shifting right any unsigned by a zero bit: U >> B0 = U
source§impl<U, B> Shr<B1> for UInt<U, B>where
U: Unsigned,
B: Bit,
impl<U, B> Shr<B1> for UInt<U, B>where U: Unsigned, B: Bit,
Shifting right a UInt
by a 1 bit: UInt<U, B> >> B1 = U
source§impl<U, B> Shr<UTerm> for UInt<U, B>where
U: Unsigned,
B: Bit,
impl<U, B> Shr<UTerm> for UInt<U, B>where U: Unsigned, B: Bit,
Shifting right UInt
by UTerm
: UInt<U, B> >> UTerm = UInt<U, B>
source§impl<U, B, Ur, Br> Shr<UInt<Ur, Br>> for UInt<U, B>where
U: Unsigned + Shr<<UInt<Ur, Br> as Sub<B1>>::Output>,
B: Bit,
Ur: Unsigned,
Br: Bit,
UInt<Ur, Br>: Sub<B1>,
impl<U, B, Ur, Br> Shr<UInt<Ur, Br>> for UInt<U, B>where U: Unsigned + Shr<<UInt<Ur, Br> as Sub<B1>>::Output>, B: Bit, Ur: Unsigned, Br: Bit, UInt<Ur, Br>: Sub<B1>,
Shifting right UInt
by UInt
: UInt(U, B) >> Y
= U >> (Y - 1)