pub trait Shl<Rhs = Self> {
type Output;
// Required method
fn shl(self, rhs: Rhs) -> Self::Output;
}
std
only.Expand description
The left 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.shl(b)
are one and the same from an evaluation
standpoint, they are different when it comes to type inference.
§Examples
An implementation of Shl
that lifts the <<
operation on integers to a
wrapper around usize
.
use std::ops::Shl;
#[derive(PartialEq, Debug)]
struct Scalar(usize);
impl Shl<Scalar> for Scalar {
type Output = Self;
fn shl(self, Self(rhs): Self) -> Self::Output {
let Self(lhs) = self;
Self(lhs << rhs)
}
}
assert_eq!(Scalar(4) << Scalar(2), Scalar(16));
An implementation of Shl
that spins a vector leftward by a given amount.
use std::ops::Shl;
#[derive(PartialEq, Debug)]
struct SpinVector<T: Clone> {
vec: Vec<T>,
}
impl<T: Clone> Shl<usize> for SpinVector<T> {
type Output = Self;
fn shl(self, rhs: usize) -> Self::Output {
// Rotate the vector by `rhs` places.
let (a, b) = self.vec.split_at(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![2, 3, 4, 0, 1] });
Required Associated Types§
Required Methods§
Implementors§
source§impl Shl<&LittleEndian<i16>> for &LittleEndian<i16>
impl Shl<&LittleEndian<i16>> for &LittleEndian<i16>
source§impl Shl<&LittleEndian<i16>> for LittleEndian<i16>
impl Shl<&LittleEndian<i16>> for LittleEndian<i16>
source§impl Shl<&LittleEndian<i32>> for &LittleEndian<i32>
impl Shl<&LittleEndian<i32>> for &LittleEndian<i32>
source§impl Shl<&LittleEndian<i32>> for LittleEndian<i32>
impl Shl<&LittleEndian<i32>> for LittleEndian<i32>
source§impl Shl<&LittleEndian<i64>> for &LittleEndian<i64>
impl Shl<&LittleEndian<i64>> for &LittleEndian<i64>
source§impl Shl<&LittleEndian<i64>> for LittleEndian<i64>
impl Shl<&LittleEndian<i64>> for LittleEndian<i64>
source§impl Shl<&LittleEndian<i128>> for &LittleEndian<i128>
impl Shl<&LittleEndian<i128>> for &LittleEndian<i128>
source§impl Shl<&LittleEndian<i128>> for LittleEndian<i128>
impl Shl<&LittleEndian<i128>> for LittleEndian<i128>
source§impl Shl<&LittleEndian<u16>> for &LittleEndian<u16>
impl Shl<&LittleEndian<u16>> for &LittleEndian<u16>
source§impl Shl<&LittleEndian<u16>> for LittleEndian<u16>
impl Shl<&LittleEndian<u16>> for LittleEndian<u16>
source§impl Shl<&LittleEndian<u32>> for &LittleEndian<u32>
impl Shl<&LittleEndian<u32>> for &LittleEndian<u32>
source§impl Shl<&LittleEndian<u32>> for LittleEndian<u32>
impl Shl<&LittleEndian<u32>> for LittleEndian<u32>
source§impl Shl<&LittleEndian<u64>> for &LittleEndian<u64>
impl Shl<&LittleEndian<u64>> for &LittleEndian<u64>
source§impl Shl<&LittleEndian<u64>> for LittleEndian<u64>
impl Shl<&LittleEndian<u64>> for LittleEndian<u64>
source§impl Shl<&LittleEndian<u128>> for &LittleEndian<u128>
impl Shl<&LittleEndian<u128>> for &LittleEndian<u128>
source§impl Shl<&LittleEndian<u128>> for LittleEndian<u128>
impl Shl<&LittleEndian<u128>> for LittleEndian<u128>
source§impl Shl<&NativeEndian<i16>> for &NativeEndian<i16>
impl Shl<&NativeEndian<i16>> for &NativeEndian<i16>
source§impl Shl<&NativeEndian<i16>> for NativeEndian<i16>
impl Shl<&NativeEndian<i16>> for NativeEndian<i16>
source§impl Shl<&NativeEndian<i32>> for &NativeEndian<i32>
impl Shl<&NativeEndian<i32>> for &NativeEndian<i32>
source§impl Shl<&NativeEndian<i32>> for NativeEndian<i32>
impl Shl<&NativeEndian<i32>> for NativeEndian<i32>
source§impl Shl<&NativeEndian<i64>> for &NativeEndian<i64>
impl Shl<&NativeEndian<i64>> for &NativeEndian<i64>
source§impl Shl<&NativeEndian<i64>> for NativeEndian<i64>
impl Shl<&NativeEndian<i64>> for NativeEndian<i64>
source§impl Shl<&NativeEndian<i128>> for &NativeEndian<i128>
impl Shl<&NativeEndian<i128>> for &NativeEndian<i128>
source§impl Shl<&NativeEndian<i128>> for NativeEndian<i128>
impl Shl<&NativeEndian<i128>> for NativeEndian<i128>
source§impl Shl<&NativeEndian<u16>> for &NativeEndian<u16>
impl Shl<&NativeEndian<u16>> for &NativeEndian<u16>
source§impl Shl<&NativeEndian<u16>> for NativeEndian<u16>
impl Shl<&NativeEndian<u16>> for NativeEndian<u16>
source§impl Shl<&NativeEndian<u32>> for &NativeEndian<u32>
impl Shl<&NativeEndian<u32>> for &NativeEndian<u32>
source§impl Shl<&NativeEndian<u32>> for NativeEndian<u32>
impl Shl<&NativeEndian<u32>> for NativeEndian<u32>
source§impl Shl<&NativeEndian<u64>> for &NativeEndian<u64>
impl Shl<&NativeEndian<u64>> for &NativeEndian<u64>
source§impl Shl<&NativeEndian<u64>> for NativeEndian<u64>
impl Shl<&NativeEndian<u64>> for NativeEndian<u64>
source§impl Shl<&NativeEndian<u128>> for &NativeEndian<u128>
impl Shl<&NativeEndian<u128>> for &NativeEndian<u128>
source§impl Shl<&NativeEndian<u128>> for NativeEndian<u128>
impl Shl<&NativeEndian<u128>> for NativeEndian<u128>
source§impl Shl<LittleEndian<i16>> for &LittleEndian<i16>
impl Shl<LittleEndian<i16>> for &LittleEndian<i16>
source§impl Shl<LittleEndian<i32>> for &LittleEndian<i32>
impl Shl<LittleEndian<i32>> for &LittleEndian<i32>
source§impl Shl<LittleEndian<i64>> for &LittleEndian<i64>
impl Shl<LittleEndian<i64>> for &LittleEndian<i64>
source§impl Shl<LittleEndian<i128>> for &LittleEndian<i128>
impl Shl<LittleEndian<i128>> for &LittleEndian<i128>
source§impl Shl<LittleEndian<u16>> for &LittleEndian<u16>
impl Shl<LittleEndian<u16>> for &LittleEndian<u16>
source§impl Shl<LittleEndian<u32>> for &LittleEndian<u32>
impl Shl<LittleEndian<u32>> for &LittleEndian<u32>
source§impl Shl<LittleEndian<u64>> for &LittleEndian<u64>
impl Shl<LittleEndian<u64>> for &LittleEndian<u64>
source§impl Shl<LittleEndian<u128>> for &LittleEndian<u128>
impl Shl<LittleEndian<u128>> for &LittleEndian<u128>
source§impl Shl<NativeEndian<i16>> for &NativeEndian<i16>
impl Shl<NativeEndian<i16>> for &NativeEndian<i16>
source§impl Shl<NativeEndian<i32>> for &NativeEndian<i32>
impl Shl<NativeEndian<i32>> for &NativeEndian<i32>
source§impl Shl<NativeEndian<i64>> for &NativeEndian<i64>
impl Shl<NativeEndian<i64>> for &NativeEndian<i64>
source§impl Shl<NativeEndian<i128>> for &NativeEndian<i128>
impl Shl<NativeEndian<i128>> for &NativeEndian<i128>
source§impl Shl<NativeEndian<u16>> for &NativeEndian<u16>
impl Shl<NativeEndian<u16>> for &NativeEndian<u16>
source§impl Shl<NativeEndian<u32>> for &NativeEndian<u32>
impl Shl<NativeEndian<u32>> for &NativeEndian<u32>
source§impl Shl<NativeEndian<u64>> for &NativeEndian<u64>
impl Shl<NativeEndian<u64>> for &NativeEndian<u64>
source§impl Shl<NativeEndian<u128>> for &NativeEndian<u128>
impl Shl<NativeEndian<u128>> for &NativeEndian<u128>
source§impl<'lhs, const N: usize> Shl<&i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<&usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<&usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<i8> for &'lhs Simd<i8, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<i16> for &'lhs Simd<i16, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<i32> for &'lhs Simd<i32, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<i64> for &'lhs Simd<i64, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<isize> for &'lhs Simd<isize, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<u8> for &'lhs Simd<u8, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<u16> for &'lhs Simd<u16, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<u32> for &'lhs Simd<u32, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<u64> for &'lhs Simd<u64, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<'lhs, const N: usize> Shl<usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
impl<'lhs, const N: usize> Shl<usize> for &'lhs Simd<usize, N>where
LaneCount<N>: SupportedLaneCount,
source§impl<U> Shl<U> for UTermwhere
U: Unsigned,
impl<U> Shl<U> for UTermwhere
U: Unsigned,
Shifting left UTerm
by an unsigned integer: UTerm << U = UTerm
source§impl<U, B> Shl<B1> for UInt<U, B>
impl<U, B> Shl<B1> for UInt<U, B>
Shifting left a UInt
by a one bit: UInt<U, B> << B1 = UInt<UInt<U, B>, B0>
source§impl<U, B> Shl<UTerm> for UInt<U, B>
impl<U, B> Shl<UTerm> for UInt<U, B>
Shifting left UInt
by UTerm
: UInt<U, B> << UTerm = UInt<U, B>
source§impl<U, B, Ur, Br> Shl<UInt<Ur, Br>> for UInt<U, B>
impl<U, B, Ur, Br> Shl<UInt<Ur, Br>> for UInt<U, B>
Shifting left UInt
by UInt
: X << Y
= UInt(X, B0) << (Y - 1)