Skip to content

Commit

Permalink
Derive default for State (#2616)
Browse files Browse the repository at this point in the history
There is no need for a manual implementation of `Default` for `State`.
It existing is distracting, hence it is removed.
  • Loading branch information
frederikrothenberger authored Sep 18, 2024
1 parent 2dc081c commit c18f7bc
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/internet_identity/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,14 @@ pub struct RateLimitState {
pub token_timestamp: Timestamp,
}

#[derive(Default)]
enum StorageState {
#[default]
Uninitialised,
Initialised(Storage<DefaultMemoryImpl>),
}

#[derive(Default)]
struct State {
storage_state: RefCell<StorageState>,
sigs: RefCell<SignatureMap>,
Expand Down Expand Up @@ -188,24 +191,6 @@ struct State {
event_data_uniqueness_counter: Cell<u16>,
}

impl Default for State {
fn default() -> Self {
Self {
storage_state: RefCell::new(StorageState::Uninitialised),
sigs: RefCell::new(SignatureMap::default()),
temp_keys: RefCell::new(TempKeys::default()),
last_upgrade_timestamp: Cell::new(0),
inflight_challenges: RefCell::new(HashMap::new()),
tentative_device_registrations: RefCell::new(HashMap::new()),
usage_metrics: RefCell::new(UsageMetrics::default()),
persistent_state: RefCell::new(PersistentState::default()),
archive_status_cache: RefCell::new(None),
registration_rate_limit: RefCell::new(None),
event_data_uniqueness_counter: Cell::new(0),
}
}
}

// Checks if salt is empty and calls `init_salt` to set it.
pub async fn ensure_salt_set() {
let salt = storage_borrow(|storage| storage.salt().cloned());
Expand Down

0 comments on commit c18f7bc

Please sign in to comment.