Skip to content

Commit e769318

Browse files
committed
Define generic AbiExample for OnceLock
1 parent c9d04bc commit e769318

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

frozen-abi/src/abi_example.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,9 @@ impl<O: AbiEnumVisitor, E: AbiEnumVisitor> AbiEnumVisitor for Result<O, E> {
555555
digester.create_child()
556556
}
557557
}
558+
559+
impl<T: AbiExample> AbiExample for std::sync::OnceLock<T> {
560+
fn example() -> Self {
561+
Self::from(T::example())
562+
}
563+
}

vote/src/vote_account.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#[cfg(RUSTC_WITH_SPECIALIZATION)]
2-
use solana_frozen_abi::abi_example::AbiExample;
31
use {
42
itertools::Itertools,
53
serde::ser::{Serialize, Serializer},
@@ -30,15 +28,15 @@ pub enum Error {
3028
InvalidOwner(/*owner:*/ Pubkey),
3129
}
3230

33-
#[derive(Debug)]
31+
#[derive(Debug, AbiExample)]
3432
struct VoteAccountInner {
3533
account: AccountSharedData,
3634
vote_state: OnceLock<Result<VoteState, Error>>,
3735
}
3836

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

41-
#[derive(Clone, Debug, Deserialize)]
39+
#[derive(Clone, Debug, Deserialize, AbiExample)]
4240
#[serde(from = "Arc<VoteAccountsHashMap>")]
4341
pub struct VoteAccounts {
4442
vote_accounts: Arc<VoteAccountsHashMap>,
@@ -321,26 +319,6 @@ impl Serialize for VoteAccounts {
321319
}
322320
}
323321

324-
#[cfg(RUSTC_WITH_SPECIALIZATION)]
325-
impl AbiExample for VoteAccountInner {
326-
fn example() -> Self {
327-
Self {
328-
account: AccountSharedData::example(),
329-
vote_state: OnceLock::from(Result::<VoteState, Error>::example()),
330-
}
331-
}
332-
}
333-
334-
#[cfg(RUSTC_WITH_SPECIALIZATION)]
335-
impl AbiExample for VoteAccounts {
336-
fn example() -> Self {
337-
Self {
338-
vote_accounts: Arc::<VoteAccountsHashMap>::example(),
339-
staked_nodes: OnceLock::from(Arc::<HashMap<Pubkey, u64>>::example()),
340-
}
341-
}
342-
}
343-
344322
#[cfg(test)]
345323
mod tests {
346324
use {

0 commit comments

Comments
 (0)