I was going through the code of open brush implementation for different tokens, and was confused at a point in PSP22 contract where there is a word written default, as shown below

default fn _emit_transfer_event(&self, _from: Option<AccountId>, _to: Option<AccountId>, _amount: Balance) {} 

which is the implementation of a trait, so here i was not able to understand why default word is used.

Some questions that are in my mind:

  • Is it used to as Default keyword used in rust or something else?
  • Is it defined in open brush to be used by itself?
  • If it is defined in open brush please do point to its implementation.

The reference to the git repo for the same can be find here.

1 Answer 1


specialization is Rust feature that allows you to override a default implementation (if the method or impl is "specialized" with the default keyword). It's like virtual in c# and C++

So you define a Trait and a generic implementation in a crate and within the contract you implement this Trait. If this impl block is empty {}, specialization will implement the most specific implementation, which is the one you defined in the file. Every generic implementation in Openbrush (PSP22, PSP34, ..) uses the default keyword that makes these functions overrideable.

without the default keyword you can not override the function body when implementing the Trait

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.