1

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

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

This is error I see when anchor build is run:

require_eq!(game_data.state,TokenState::Initial,TokenError::NotAtInitialState);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `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?

5
  • What's the type of the values you're comparing
    – Ademola
    Commented 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
    Commented Jul 27, 2022 at 21:27
  • @Ademola it is a custom enum TokenState.
    – CryptoSar
    Commented Jul 28, 2022 at 7:15
  • @trent.sol I have updated the error in the question, thanks.
    – CryptoSar
    Commented 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
    Commented Jul 28, 2022 at 20:33

1 Answer 1

5

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 you have read our privacy policy.

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