Skip to content

Commit d610418

Browse files
committed
TryFrom i StakeStateV2Tag
1 parent 089b8d8 commit d610418

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

pinocchio/interface/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ homepage = { workspace = true }
88
license = { workspace = true }
99

1010
[dependencies]
11-
wincode = { version = "0.4.4", features = ["derive"] }
1211
solana-address = { version = "2.2.0", features = ["wincode"] }
13-
1412
spl-pod = { version = "0.8.0", features = ["wincode"] }
13+
wincode = { version = "0.4.4", features = ["derive"] }
1514

1615
[dev-dependencies]
1716
bincode = "1.3.3"

pinocchio/interface/src/state.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ pub enum StakeStateV2Tag {
7979
impl StakeStateV2Tag {
8080
pub const TAG_LEN: usize = size_of::<PodU32>();
8181

82-
#[inline]
83-
pub(crate) fn from_u32(v: u32) -> Result<Self, StakeStateError> {
84-
Self::assert_valid_tag(v)?;
85-
Ok(unsafe { core::mem::transmute::<u32, StakeStateV2Tag>(v) })
86-
}
87-
8882
#[inline]
8983
pub(crate) unsafe fn from_u32_unchecked(v: u32) -> Self {
9084
debug_assert!(v <= Self::RewardsPool as u32);
@@ -105,7 +99,17 @@ impl StakeStateV2Tag {
10599
return Err(StakeStateError::UnexpectedEof);
106100
}
107101
let raw = u32::from_le_bytes(bytes[..Self::TAG_LEN].try_into().unwrap());
108-
Self::from_u32(raw)
102+
Self::try_from(raw)
103+
}
104+
}
105+
106+
impl TryFrom<u32> for StakeStateV2Tag {
107+
type Error = StakeStateError;
108+
109+
#[inline]
110+
fn try_from(v: u32) -> Result<Self, Self::Error> {
111+
Self::assert_valid_tag(v)?;
112+
Ok(unsafe { Self::from_u32_unchecked(v) })
109113
}
110114
}
111115

0 commit comments

Comments
 (0)