ToBytes — SIMD 값을 바이트로 변환하는 트레잇

ToBytes — SIMD 값을 바이트로 변환하는 트레잇

ToBytes는 SIMD 값을 바이트 표현으로 변환하는 트레잇이에요. nightly 전용 실험 API(portable_simd, #86656)이에요.

출처: Rust 공식 문서

본문

pub trait ToBytes: Sealed {
    type Bytes: Copy + Unpin + Send + Sync + AsRef<[u8]> + AsMut<[u8]> + SimdUint<Scalar = u8> + 'static;

    // 필수 메서드
    fn to_ne_bytes(self) -> Self::Bytes;
    fn to_be_bytes(self) -> Self::Bytes;
    fn to_le_bytes(self) -> Self::Bytes;
    fn from_ne_bytes(bytes: Self::Bytes) -> Self;
    fn from_be_bytes(bytes: Self::Bytes) -> Self;
    fn from_le_bytes(bytes: Self::Bytes) -> Self;
}

필수 메서드

// 네이티브 엔디언으로 바이트 변환해요.
fn to_ne_bytes(self) -> Self::Bytes;
// 빅 엔디언으로 바이트 변환해요.
fn to_be_bytes(self) -> Self::Bytes;
// 리틀 엔디언으로 바이트 변환해요.
fn to_le_bytes(self) -> Self::Bytes;

정수 SIMD 타입(Simd<u8,N> 등)이 이 트레잇을 구현해요.

더 알아보기 (Learn more)