# Trait std::ops::Shr1.0.0 [−] [src]

#[lang = "shr"]
pub trait Shr<RHS> { type Output; fn shr(self, rhs: RHS) -> Self::Output; }

The right shift operator >>.

# 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, Scalar(rhs): Self) -> Scalar {
let Scalar(lhs) = self;
Scalar(lhs >> rhs)
}
}

assert_eq!(Scalar(16) >> Scalar(2), Scalar(4));Run

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) -> SpinVector<T> {
// Rotate the vector by `rhs` places.
let (a, b) = self.vec.split_at(self.vec.len() - rhs);
let mut spun_vector: Vec<T> = vec![];
spun_vector.extend_from_slice(b);
spun_vector.extend_from_slice(a);
SpinVector { vec: spun_vector }
}
}

assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } >> 2,
SpinVector { vec: vec![3, 4, 0, 1, 2] });Run

## Associated Types

### type Output

The resulting type after applying the >> operator.

## Required Methods

### fn shr(self, rhs: RHS) -> Self::Output

Performs the >> operation.