Define generic AbiExample for OnceLock (#33520)
* Define generic AbiExample for OnceLock * Guard with cfg... cargo-test-sbf (governance/addin-mock/program, governance/program): error[E0658]: use of unstable library feature 'once_cell' --> src/abi_example.rs:559:36 | 559 | impl<T: AbiExample> AbiExample for std::sync::OnceLock<T> { | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #74465 <https://github.com/rust-lang/rust/issues/74465> for more information = help: add `#![feature(once_cell)]` to the crate attributes to enable
This commit is contained in:
parent
c9d04bcfe6
commit
05ddbf3b91
|
@ -555,3 +555,10 @@ impl<O: AbiEnumVisitor, E: AbiEnumVisitor> AbiEnumVisitor for Result<O, E> {
|
||||||
digester.create_child()
|
digester.create_child()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "solana"))]
|
||||||
|
impl<T: AbiExample> AbiExample for std::sync::OnceLock<T> {
|
||||||
|
fn example() -> Self {
|
||||||
|
Self::from(T::example())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
|
||||||
use solana_frozen_abi::abi_example::AbiExample;
|
|
||||||
use {
|
use {
|
||||||
itertools::Itertools,
|
itertools::Itertools,
|
||||||
serde::ser::{Serialize, Serializer},
|
serde::ser::{Serialize, Serializer},
|
||||||
|
@ -30,7 +28,7 @@ pub enum Error {
|
||||||
InvalidOwner(/*owner:*/ Pubkey),
|
InvalidOwner(/*owner:*/ Pubkey),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, AbiExample)]
|
||||||
struct VoteAccountInner {
|
struct VoteAccountInner {
|
||||||
account: AccountSharedData,
|
account: AccountSharedData,
|
||||||
vote_state: OnceLock<Result<VoteState, Error>>,
|
vote_state: OnceLock<Result<VoteState, Error>>,
|
||||||
|
@ -38,7 +36,7 @@ struct VoteAccountInner {
|
||||||
|
|
||||||
pub type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;
|
pub type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize, AbiExample)]
|
||||||
#[serde(from = "Arc<VoteAccountsHashMap>")]
|
#[serde(from = "Arc<VoteAccountsHashMap>")]
|
||||||
pub struct VoteAccounts {
|
pub struct VoteAccounts {
|
||||||
vote_accounts: Arc<VoteAccountsHashMap>,
|
vote_accounts: Arc<VoteAccountsHashMap>,
|
||||||
|
@ -321,26 +319,6 @@ impl Serialize for VoteAccounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
|
||||||
impl AbiExample for VoteAccountInner {
|
|
||||||
fn example() -> Self {
|
|
||||||
Self {
|
|
||||||
account: AccountSharedData::example(),
|
|
||||||
vote_state: OnceLock::from(Result::<VoteState, Error>::example()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(RUSTC_WITH_SPECIALIZATION)]
|
|
||||||
impl AbiExample for VoteAccounts {
|
|
||||||
fn example() -> Self {
|
|
||||||
Self {
|
|
||||||
vote_accounts: Arc::<VoteAccountsHashMap>::example(),
|
|
||||||
staked_nodes: OnceLock::from(Arc::<HashMap<Pubkey, u64>>::example()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use {
|
use {
|
||||||
|
|
Loading…
Reference in New Issue