alloy_sol_types/types/
enum.rs1use crate::{abi::token::WordToken, Result, SolType, Word};
2use alloc::vec::Vec;
3
4pub trait SolEnum: Sized + Copy + Into<u8> + TryFrom<u8, Error = crate::Error> {
12 const COUNT: usize;
16
17 #[inline]
19 fn tokenize(self) -> WordToken {
20 WordToken(Word::with_last_byte(self.into()))
21 }
22
23 #[inline]
25 fn abi_decode(data: &[u8], validate: bool) -> Result<Self> {
26 <crate::sol_data::Uint<8> as SolType>::abi_decode(data, validate).and_then(Self::try_from)
27 }
28
29 #[inline]
31 fn abi_encode_raw(self, out: &mut Vec<u8>) {
32 out.extend(self.tokenize().0);
33 }
34
35 #[inline]
37 fn abi_encode(self) -> Vec<u8> {
38 self.tokenize().0.to_vec()
39 }
40}