You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: num256.rs
    path of file: ./repos/risingwave/src/common/src/types
    
    the code of the file until where you have to start completion: // Copyright 2024 RisingWave Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt::{Display, Formatter, Write};
use std::hash::Hasher;
use std::io::Read;
use std::mem;
use std::num::ParseIntError;
use std::ops::{Add, Div, Mul, Neg, Rem, Sub};
use std::str::FromStr;

use bytes::{BufMut, Bytes};
use ethnum::{i256, u256, AsI256};
use num_traits::{
    CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedSub, Num, One, Zero,
};
use risingwave_pb::data::ArrayType;
use serde::{Deserialize, Serialize};
use to_text::ToText;

use crate::array::ArrayResult;
use crate::estimate_size::EstimateSize;
use crate::types::to_binary::ToBinary;
use crate::types::{to_text, Buf, DataType, Scalar, ScalarRef, F64};

/// A 256-bit signed integer.
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Default, Hash)]
pub struct Int256(pub(crate) Box<i256>);

/// A reference to an `Int256` value.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub struct Int256Ref<'a>(pub &'a i256);

impl<'a> Display for Int256Ref<'a> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        self.write(f)
    }
}

macro_rules! impl_common_for_num256 {
    ($scalar:ident, $scalar_ref:ident < $gen:tt > , $inner:ty, $array_type:ident) => {
        impl Scalar for $scalar {
            type ScalarRefType<$gen> = $scalar_ref<$gen>;

            fn as_scalar_ref(&self) -> Self::ScalarRefType<'_> {
                $scalar_ref(self.0.as_ref())
            }
        }

        impl<$gen> ScalarRef<$gen> for $scalar_ref<$gen> {
            type ScalarType = $scalar;

            fn to_owned_scalar(&self) -> Self::ScalarType {
                $scalar((*self.0).into())
            }

            fn hash_scalar<H: Hasher>(&self, state: &mut H) {
                use std::hash::Hash as _;
                self.0.hash(state)
            }
        }

        impl FromStr for $scalar {
            type Err = ParseIntError;

            fn from_str(s: &str) -> Result<Self, Self::Err> {
                <$inner>::from_str(s).map(Into::into)
            }
        }

        impl $scalar {
            #[inline]
            pub fn min_value() -> Self {
                Self::from(<$inner>::MIN)
            }

            #[inline]
            pub fn max_value() -> Self {
                Self::from(<$inner>::MAX)
            }

            #[inline]
            pub fn into_inner(self) -> $inner {
                *self.0
            }

            #[inline]
            pub const fn size() -> usize {
                mem::size_of::<$inner>()
            }

            #[inline]
            pub fn array_type() -> ArrayType {
                ArrayType::$array_type
            }

            #[inline]
            pub fn from_ne_bytes(bytes: [u8; mem::size_of::<$inner>()]) -> Self {
                Self(Box::new(<$inner>::from_ne_bytes(bytes)))
            }

            #[inline]
            pub fn from_le_bytes(bytes: [u8; mem::size_of::<$inner>()]) -> Self {
                Self(Box::new(<$inner>::from_le_bytes(bytes)))
            }

            #[inline]
            pub fn from_be_bytes(bytes: [u8; mem::size_of::<$inner>()]) -> Self {
                Self(Box::new(<$inner>::from_be_bytes(bytes)))
            }

            pub fn from_protobuf(input: &mut impl Read) -> ArrayResult<Self> {
                let mut buf = [0u8; mem::size_of::<$inner>()];
                input.read_exact(&mut buf)?;
                Ok(Self::from_be_bytes(buf))
            }
        }

        impl From<$inner> for $scalar {
            fn from(value: $inner) -> Self {
                Self(Box::new(value))
            }
        }

        impl $scalar_ref<'_> {
            #[inline]
            pub fn to_le_bytes(self) -> [u8; mem::size_of::<$inner>()] {
                self.0.to_le_bytes()
            }

            #[inline]
            pub fn to_be_bytes(self) -> [u8; mem::size_of::<$inner>()] {
                self.0.to_be
    
    fn hex_to_int256() {
        assert_eq!(Int256::from_str_hex("0x0").unwrap(), Int256::from(0));
        assert_eq!(Int256::from_str_hex("0x1").unwrap(), Int256::from(1));
        assert_eq!(
            Int256::from_str_hex(
                "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
            )
            .unwrap(),
            Int256::from(-1)
        );
        assert_eq!(Int256::from_str_hex("0xa").unwrap(), Int256::from(10));
        assert_eq!(Int256::from_str_hex("0xA").unwrap(), Int256::from(10));
        assert_eq!(Int256::from_str_hex("0Xff").unwrap(), Int256::from(255));

        assert_eq!(
            Int256::from_str_hex(
                "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01"
            )
            .unwrap(),
            Int256::from(-255)
        );

        assert_eq!(
            Int256::from_str_hex("0xf").unwrap(),
            Int256::from_str("15").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffff").unwrap(),
            Int256::from_str("1048575").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffff").unwrap(),
            Int256::from_str("68719476735").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffff").unwrap(),
            Int256::from_str("4503599627370495").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffff").unwrap(),
            Int256::from_str("295147905179352825855").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffff").unwrap(),
            Int256::from_str("19342813113834066795298815").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffff").unwrap(),
            Int256::from_str("1267650600228229401496703205375").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffff").unwrap(),
            Int256::from_str("83076749736557242056487941267521535").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffff").unwrap(),
            Int256::from_str("5444517870735015415413993718908291383295").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffff").unwrap(),
            Int256::from_str("356811923176489970264571492362373784095686655").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffffffff").unwrap(),
            Int256::from_str("23384026197294446691258957323460528314494920687615").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffffffffffff").unwrap(),
            Int256::from_str("1532495540865888858358347027150309183618739122183602175").unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffffffffffffffff").unwrap(),
            Int256::from_str("100433627766186892221372630771322662657637687111424552206335")
                .unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffffffffffffffffffff")
                .unwrap(),
            Int256::from_str("6582018229284824168619876730229402019930943462534319453394436095")
                .unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
                .unwrap(),
            Int256::from_str(
                "431359146674410236714672241392314090778194310760649159697657763987455"
            )
            .unwrap()
        );
        assert_eq!(
            Int256::from_str_hex("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
                .unwrap(),
            Int256::from_str(
                "28269553036454149273332760011886696253239742350009903329945699220681916415"
            )
            .unwrap()
        );

        // int256 max
        assert_eq!(
            Int256::from_str_hex(
                "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
            )
            .unwrap(),
            Int256::max_value(),
        );

        // int256 min
        assert_eq!(
            Int256::from_str_hex(
                "0x8000000000000000000000000000000000000000000000000000000000000000"
            )
            .unwrap(),
            Int256::min_value(),
        );
    }