use crate::{
Result, SolType, Word,
abi::{AbiDecoderConfig, token::WordToken},
};
use alloc::vec::Vec;
pub trait SolEnum: Sized + Copy + Into<u8> + TryFrom<u8, Error = crate::Error> {
const COUNT: usize;
#[inline]
fn tokenize(self) -> WordToken {
WordToken(Word::with_last_byte(self.into()))
}
#[inline]
fn abi_decode(data: &[u8]) -> Result<Self> {
<crate::sol_data::Uint<8> as SolType>::abi_decode(data).and_then(Self::try_from)
}
#[inline]
fn abi_decode_with_config(data: &[u8], config: AbiDecoderConfig) -> Result<Self> {
<crate::sol_data::Uint<8> as SolType>::abi_decode_with_config(data, config)
.and_then(Self::try_from)
}
#[inline]
fn abi_decode_validate(data: &[u8]) -> Result<Self> {
Self::abi_decode_with_config(data, AbiDecoderConfig::new().validate(true))
}
#[inline]
fn abi_encode_raw(self, out: &mut Vec<u8>) {
out.extend(self.tokenize().0);
}
#[inline]
fn abi_encode(self) -> Vec<u8> {
self.tokenize().0.to_vec()
}
}