pub trait Shr<Rhs = Self> {
type Output;
// Required method
fn shr(self, rhs: Rhs) -> Self::Output;
}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<'a, A, B, S, S2, D, E> Shr<&'a ArrayBase<S2, E>> for &'a ArrayBase<S, D>
Perform elementwise
right shift
between references self and rhs,
and return the result as a new Array.
impl<'a, A, B, S, S2, D, E> Shr<&'a ArrayBase<S2, E>> for &'a ArrayBase<S, D>
Perform elementwise
right shift
between references self and rhs,
and return the result as a new Array.
If their shapes disagree, self and rhs is broadcast to their broadcast shape,
cloning the data if needed.
Panics if broadcasting isn’t possible.
Source§impl<'a, A, B, S, S2, D, E> Shr<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
Perform elementwise
right shift
between self and reference rhs,
and return the result.
impl<'a, A, B, S, S2, D, E> Shr<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
Perform elementwise
right shift
between self and reference rhs,
and return the result.
rhs must be an Array or ArcArray.
If their shapes disagree, self is broadcast to their broadcast shape,
cloning the data if needed.
Panics if broadcasting isn’t possible.
Source§impl<'a, A, B, S, S2, D, E> Shr<ArrayBase<S2, E>> for &'a ArrayBase<S, D>
Perform elementwise
right shift
between reference self and rhs,
and return the result.
impl<'a, A, B, S, S2, D, E> Shr<ArrayBase<S2, E>> for &'a ArrayBase<S, D>
Perform elementwise
right shift
between reference self and rhs,
and return the result.
rhs must be an Array or ArcArray.
If their shapes disagree, self is broadcast to their broadcast shape,
cloning the data if needed.
Panics if broadcasting isn’t possible.
Source§impl<'a, A, S, D, B> Shr<B> for &'a ArrayBase<S, D>
Perform elementwise
right shift
between the reference self and the scalar x,
and return the result as a new Array.
impl<'a, A, S, D, B> Shr<B> for &'a ArrayBase<S, D>
Perform elementwise
right shift
between the reference self and the scalar x,
and return the result as a new Array.
Source§impl<'lhs, const N: usize> Shr<&i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<&usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<&usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<'lhs, const N: usize> Shr<usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shr<usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
Source§impl<A, B, S, S2, D, E> Shr<ArrayBase<S2, E>> for ArrayBase<S, D>
Perform elementwise
right shift
between self and rhs,
and return the result.
impl<A, B, S, S2, D, E> Shr<ArrayBase<S2, E>> for ArrayBase<S, D>
Perform elementwise
right shift
between self and rhs,
and return the result.
self must be an Array or ArcArray.
If their shapes disagree, self is broadcast to their broadcast shape.
Panics if broadcasting isn’t possible.
Source§impl<A, S, D, B> Shr<B> for ArrayBase<S, D>
Perform elementwise
right shift
between self and the scalar x,
and return the result (based on self).
impl<A, S, D, B> Shr<B> for ArrayBase<S, D>
Perform elementwise
right shift
between self and the scalar x,
and return the result (based on self).
self must be an Array or ArcArray.