Trait snarkvm_circuit::environment::prelude::Shl
1.0.0 · source · pub trait Shl<Rhs = Self> {
type Output;
// Required method
fn shl(self, rhs: Rhs) -> Self::Output;
}
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§
Trait Implementations§
§impl<E, I> Metrics<dyn Shl<Integer<E, I>, Output = Integer<E, I>>> for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> Metrics<dyn Shl<Integer<E, I>, Output = Integer<E, I>>> for Integer<E, I>where E: Environment, I: IntegerType,
§impl<E, I> OutputMode<dyn Shl<Integer<E, I>, Output = Integer<E, I>>> for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> OutputMode<dyn Shl<Integer<E, I>, Output = Integer<E, I>>> for Integer<E, I>where E: Environment, I: IntegerType,
type Case = (Mode, Mode)
§fn output_mode(
case: &<Integer<E, I> as OutputMode<dyn Shl<Integer<E, I>, Output = Integer<E, I>>>>::Case
) -> Mode
fn output_mode( case: &<Integer<E, I> as OutputMode<dyn Shl<Integer<E, I>, Output = Integer<E, I>>>>::Case ) -> Mode
Implementors§
source§impl Shl<usize> for Saturating<i8>
impl Shl<usize> for Saturating<i8>
type Output = Saturating<i8>
source§impl Shl<usize> for Saturating<i16>
impl Shl<usize> for Saturating<i16>
type Output = Saturating<i16>
source§impl Shl<usize> for Saturating<i32>
impl Shl<usize> for Saturating<i32>
type Output = Saturating<i32>
source§impl Shl<usize> for Saturating<i64>
impl Shl<usize> for Saturating<i64>
type Output = Saturating<i64>
source§impl Shl<usize> for Saturating<i128>
impl Shl<usize> for Saturating<i128>
type Output = Saturating<i128>
source§impl Shl<usize> for Saturating<isize>
impl Shl<usize> for Saturating<isize>
type Output = Saturating<isize>
source§impl Shl<usize> for Saturating<u8>
impl Shl<usize> for Saturating<u8>
type Output = Saturating<u8>
source§impl Shl<usize> for Saturating<u16>
impl Shl<usize> for Saturating<u16>
type Output = Saturating<u16>
source§impl Shl<usize> for Saturating<u32>
impl Shl<usize> for Saturating<u32>
type Output = Saturating<u32>
source§impl Shl<usize> for Saturating<u64>
impl Shl<usize> for Saturating<u64>
type Output = Saturating<u64>
source§impl Shl<usize> for Saturating<u128>
impl Shl<usize> for Saturating<u128>
type Output = Saturating<u128>
source§impl Shl<usize> for Saturating<usize>
impl Shl<usize> for Saturating<usize>
type Output = Saturating<usize>
source§impl<'lhs, 'rhs, T, const LANES: usize> Shl<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES>where
T: SimdElement,
Simd<T, LANES>: Shl<Simd<T, LANES>, Output = Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
impl<'lhs, 'rhs, T, const LANES: usize> Shl<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES>where T: SimdElement, Simd<T, LANES>: Shl<Simd<T, LANES>, Output = Simd<T, LANES>>, LaneCount<LANES>: SupportedLaneCount,
§impl<E, I, M> Shl<&Integer<E, M>> for &Integer<E, I>where
E: Environment,
I: IntegerType,
M: Magnitude,
impl<E, I, M> Shl<&Integer<E, M>> for &Integer<E, I>where E: Environment, I: IntegerType, M: Magnitude,
§impl<E, I, M> Shl<&Integer<E, M>> for Integer<E, I>where
E: Environment,
I: IntegerType,
M: Magnitude,
impl<E, I, M> Shl<&Integer<E, M>> for Integer<E, I>where E: Environment, I: IntegerType, M: Magnitude,
§impl<E, I, M> Shl<&Integer<E, M>> for Integer<E, I>where
E: Environment,
I: IntegerType,
M: Magnitude,
impl<E, I, M> Shl<&Integer<E, M>> for Integer<E, I>where E: Environment, I: IntegerType, M: Magnitude,
§impl<E, I, M> Shl<Integer<E, M>> for &Integer<E, I>where
E: Environment,
I: IntegerType,
M: Magnitude,
impl<E, I, M> Shl<Integer<E, M>> for &Integer<E, I>where E: Environment, I: IntegerType, M: Magnitude,
§impl<E, I, M> Shl<Integer<E, M>> for Integer<E, I>where
E: Environment,
I: IntegerType,
M: Magnitude,
impl<E, I, M> Shl<Integer<E, M>> for Integer<E, I>where E: Environment, I: IntegerType, M: Magnitude,
§impl<E, I, M> Shl<Integer<E, M>> for Integer<E, I>where
E: Environment,
I: IntegerType,
M: Magnitude,
impl<E, I, M> Shl<Integer<E, M>> for Integer<E, I>where E: Environment, I: IntegerType, M: Magnitude,
source§impl<T, const LANES: usize> Shl<&Simd<T, LANES>> for Simd<T, LANES>where
T: SimdElement,
Simd<T, LANES>: Shl<Simd<T, LANES>, Output = Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> Shl<&Simd<T, LANES>> for Simd<T, LANES>where T: SimdElement, Simd<T, LANES>: Shl<Simd<T, LANES>, Output = Simd<T, LANES>>, LaneCount<LANES>: SupportedLaneCount,
source§impl<T, const LANES: usize> Shl<Simd<T, LANES>> for &Simd<T, LANES>where
T: SimdElement,
Simd<T, LANES>: Shl<Simd<T, LANES>, Output = Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> Shl<Simd<T, LANES>> for &Simd<T, LANES>where T: SimdElement, Simd<T, LANES>: Shl<Simd<T, LANES>, Output = Simd<T, LANES>>, LaneCount<LANES>: 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<B0> for UInt<U, B>where
U: Unsigned,
B: Bit,
impl<U, B> Shl<B0> for UInt<U, B>where U: Unsigned, B: Bit,
Shifting left any unsigned by a zero bit: U << B0 = U
source§impl<U, B> Shl<B1> for UInt<U, B>where
U: Unsigned,
B: Bit,
impl<U, B> Shl<B1> for UInt<U, B>where U: Unsigned, B: Bit,
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>where
U: Unsigned,
B: Bit,
impl<U, B> Shl<UTerm> for UInt<U, B>where U: Unsigned, B: Bit,
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>where
U: Unsigned,
B: Bit,
Ur: Unsigned,
Br: Bit,
UInt<Ur, Br>: Sub<B1>,
UInt<UInt<U, B>, B0>: Shl<<UInt<Ur, Br> as Sub<B1>>::Output>,
impl<U, B, Ur, Br> Shl<UInt<Ur, Br>> for UInt<U, B>where U: Unsigned, B: Bit, Ur: Unsigned, Br: Bit, UInt<Ur, Br>: Sub<B1>, UInt<UInt<U, B>, B0>: Shl<<UInt<Ur, Br> as Sub<B1>>::Output>,
Shifting left UInt
by UInt
: X << Y
= UInt(X, B0) << (Y - 1)