Skip to content

Commit b36f96e

Browse files
committed
specifier, fmt
1 parent f5af464 commit b36f96e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

sysvar/src/epoch_schedule.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@
119119
//! #
120120
//! # Ok::<(), anyhow::Error>(())
121121
//! ```
122-
use crate::Sysvar;
123122
#[cfg(feature = "bincode")]
124123
use crate::SysvarSerialize;
124+
use {crate::Sysvar, solana_program_error::ProgramError};
125125
pub use {
126126
solana_epoch_schedule::EpochSchedule,
127127
solana_sdk_ids::sysvar::epoch_schedule::{check_id, id, ID},
@@ -187,21 +187,23 @@ impl PodEpochSchedule {
187187
}
188188
}
189189

190-
impl From<PodEpochSchedule> for EpochSchedule {
191-
fn from(pod: PodEpochSchedule) -> Self {
192-
Self {
190+
impl TryFrom<PodEpochSchedule> for EpochSchedule {
191+
type Error = ProgramError;
192+
193+
fn try_from(pod: PodEpochSchedule) -> Result<Self, Self::Error> {
194+
Ok(Self {
193195
slots_per_epoch: pod.slots_per_epoch(),
194196
leader_schedule_slot_offset: pod.leader_schedule_slot_offset(),
195-
warmup: pod.warmup(),
197+
warmup: pod.warmup()?,
196198
first_normal_epoch: pod.first_normal_epoch(),
197199
first_normal_slot: pod.first_normal_slot(),
198-
}
200+
})
199201
}
200202
}
201203

202204
impl Sysvar for EpochSchedule {
203205
fn get() -> Result<Self, solana_program_error::ProgramError> {
204-
Ok(Self::from(PodEpochSchedule::fetch()?))
206+
PodEpochSchedule::fetch()?.try_into()
205207
}
206208
}
207209

@@ -222,7 +224,7 @@ mod tests {
222224
first_normal_slot: 524256u64.to_le_bytes(),
223225
};
224226

225-
let epoch_schedule = EpochSchedule::from(pod);
227+
let epoch_schedule = EpochSchedule::try_from(pod).unwrap();
226228

227229
assert_eq!(epoch_schedule.slots_per_epoch, 432000);
228230
assert_eq!(epoch_schedule.leader_schedule_slot_offset, 432000);

0 commit comments

Comments
 (0)