sdk: Make `declare_id` mostly const (#30177)
This commit is contained in:
parent
55c8963462
commit
0481ce3069
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue