Shl

Shl (왼쪽 시프트 연산자 트레이트)

왼쪽 시프트 연산자 <<를 위한 트레이트예요.

출처: Rust 공식 문서

본문

Rhs는 기본적으로 Self이지만, 이것이 필수는 아니에요.

pub trait Shl<Rhs = Self> {
    type Output;

    // 필수 메서드
    fn shl(self, rhs: Rhs) -> Self::Output;
}

예시

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)
    }
}

더 알아보기 (Learn more)

Rust 공식 문서