pub trait Discriminator {
const DISCRIMINATOR: &'static [u8];
}
Expand description
Unique identifier for a type.
This is not a trait you should derive manually, as various Anchor macros already derive it internally.
Prior to Anchor v0.31, discriminators were always 8 bytes in size. However, starting with Anchor v0.31, it is possible to override the default discriminators, and discriminator length is no longer fixed, which means this trait can also be implemented for non-Anchor programs.
It’s important that the discriminator is always unique for the type you’re implementing it for. While the discriminator can be at any length (including zero), the IDL generation does not currently allow empty discriminators for safety and convenience reasons. However, the trait definition still allows empty discriminators because some non-Anchor programs, e.g. the SPL Token program, don’t have account discriminators. In that case, safety checks should never depend on the discriminator.
Required Associated Constants§
Sourceconst DISCRIMINATOR: &'static [u8]
const DISCRIMINATOR: &'static [u8]
Discriminator slice.
See Discriminator
trait documentation for more information.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.