I am trying to use the following code but it isn't working:


This is error I see when anchor build is run:

    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `game::TokenState` cannot be formatted with the default formatter

However, the same code works if I use require! macro:

require!(self.state == TokenState::Initial,TokenError::NotAtInitialState);

Is it because I am not using a particular trait required for the custom type? If yes then what is this trait?

  • What's the type of the values you're comparing
    – Ademola
    Jul 27, 2022 at 20:58
  • can you elaborate "not working"? stating explicitly how you believe it should work and what you're observing instead would be helpful
    – trent.sol
    Jul 27, 2022 at 21:27
  • @Ademola it is a custom enum TokenState.
    – CryptoSar
    Jul 28, 2022 at 7:15
  • @trent.sol I have updated the error in the question, thanks.
    – CryptoSar
    Jul 28, 2022 at 7:20
  • Ah I see. Looks like your question's gotten a satisfactory answer though. You could probably close this issue
    – Ademola
    Jul 28, 2022 at 20:33

1 Answer 1


game::TokenState cannot be formatted with the default formatter

Deep in the bowels of require_eq!(), to_string() is called on your type TokenState. This method requires that the std::fmt::Display trait be implemented on TokenState.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.