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

Commit 05ddbf3

Browse files
authored
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 <rust-lang/rust#74465> for more information = help: add `#![feature(once_cell)]` to the crate attributes to enable
1 parent c9d04bc commit 05ddbf3

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

frozen-abi/src/abi_example.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,10 @@ impl<O: AbiEnumVisitor, E: AbiEnumVisitor> AbiEnumVisitor for Result<O, E> {
555555
digester.create_child()
556556
}
557557
}
558+
559+
#[cfg(not(target_os = "solana"))]
560+
impl<T: AbiExample> AbiExample for std::sync::OnceLock<T> {
561+
fn example() -> Self {
562+
Self::from(T::example())
563+
}
564+
}

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)