sdk: Make `declare_id` mostly const (#30177)

This commit is contained in:
Jon Cinque 2023-02-09 01:26:09 +01:00 committed by GitHub
parent 55c8963462
commit 0481ce3069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -44,16 +44,18 @@ fn id_to_tokens(
tokens: &mut proc_macro2::TokenStream, tokens: &mut proc_macro2::TokenStream,
) { ) {
tokens.extend(quote! { tokens.extend(quote! {
/// The static program ID. /// The const program ID.
pub static ID: #pubkey_type = #id; pub const ID: #pubkey_type = #id;
/// Returns `true` if given pubkey is the program ID. /// Returns `true` if given pubkey is the program ID.
// TODO make this const once `derive_const` makes it out of nightly
// and we can `derive_const(PartialEq)` on `Pubkey`.
pub fn check_id(id: &#pubkey_type) -> bool { pub fn check_id(id: &#pubkey_type) -> bool {
id == &ID id == &ID
} }
/// Returns the program ID. /// Returns the program ID.
pub fn id() -> #pubkey_type { pub const fn id() -> #pubkey_type {
ID ID
} }