account_state.rs 921 B

123456789101112131415161718192021222324252627282930
  1. use pinocchio::program_error::ProgramError;
  2. #[repr(u8)]
  3. #[derive(Clone, Copy, Debug, PartialEq)]
  4. pub enum AccountState {
  5. /// Account is not yet initialized
  6. Uninitialized,
  7. /// Account is initialized; the account owner and/or delegate may perform
  8. /// permitted operations on this account
  9. Initialized,
  10. /// Account has been frozen by the mint freeze authority. Neither the
  11. /// account owner nor the delegate are able to perform operations on
  12. /// this account.
  13. Frozen,
  14. }
  15. impl TryFrom<u8> for AccountState {
  16. type Error = ProgramError;
  17. #[inline(always)]
  18. fn try_from(value: u8) -> Result<Self, Self::Error> {
  19. match value {
  20. // SAFETY: `value` is guaranteed to be in the range of the enum variants.
  21. 0..=2 => Ok(unsafe { core::mem::transmute::<u8, AccountState>(value) }),
  22. _ => Err(ProgramError::InvalidAccountData),
  23. }
  24. }
  25. }