Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Define generic AbiExample for OnceLock #33520

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,10 @@ impl<O: AbiEnumVisitor, E: AbiEnumVisitor> AbiEnumVisitor for Result<O, E> {
digester.create_child()
}
}

#[cfg(not(target_os = "solana"))]
impl<T: AbiExample> AbiExample for std::sync::OnceLock<T> {
fn example() -> Self {
Self::from(T::example())
}
}
26 changes: 2 additions & 24 deletions vote/src/vote_account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::AbiExample;
use {
itertools::Itertools,
serde::ser::{Serialize, Serializer},
Expand Down Expand Up @@ -30,15 +28,15 @@ pub enum Error {
InvalidOwner(/*owner:*/ Pubkey),
}

#[derive(Debug)]
#[derive(Debug, AbiExample)]
struct VoteAccountInner {
account: AccountSharedData,
vote_state: OnceLock<Result<VoteState, Error>>,
}

pub type VoteAccountsHashMap = HashMap<Pubkey, (/*stake:*/ u64, VoteAccount)>;

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, AbiExample)]
#[serde(from = "Arc<VoteAccountsHashMap>")]
pub struct VoteAccounts {
vote_accounts: Arc<VoteAccountsHashMap>,
Expand Down Expand Up @@ -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)]
mod tests {
use {
Expand Down