Skip to content

refactor: mark enabled ephemeral timer duration as NonZero - #8495

Merged
link2xt merged 1 commit into
mainfrom
link2xt/ephemeral-timer-duration-nonzero
Jul 31, 2026
Merged

refactor: mark enabled ephemeral timer duration as NonZero#8495
link2xt merged 1 commit into
mainfrom
link2xt/ephemeral-timer-duration-nonzero

Conversation

@link2xt

@link2xt link2xt commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Now the type system ensures that Timer::Enabled
never stores 0 value inside accidentally,
it is impossible to put 0 there without unsafe code.

Comment thread src/ephemeral.rs
Enabled {
/// Timer duration in seconds.
///
/// The value cannot be 0.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most interesting change is here.

@link2xt

link2xt commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Slightly related to #8493, in the end the timer is stored in SQLite with 0 treated as a special value.

Comment thread src/ephemeral.rs
if duration == 0 {
Self::Disabled
} else {
if let Some(duration) = NonZero::<u32>::new(duration) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the only code that got less ugly as a result.

Comment thread src/ephemeral.rs
Err(rusqlite::types::FromSqlError::OutOfRange(value))
}
})
u32::column_result(value).map(Self::from_u32)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have been done independently of the NonZero change.

Comment thread src/ephemeral/ephemeral_tests.rs Outdated
Comment thread src/ephemeral.rs Outdated
Comment thread src/ephemeral.rs Outdated
@link2xt
link2xt force-pushed the link2xt/ephemeral-timer-duration-nonzero branch 3 times, most recently from 54585ba to 43e958e Compare July 31, 2026 21:58

@hpk42 hpk42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@link2xt
link2xt force-pushed the link2xt/ephemeral-timer-duration-nonzero branch from 43e958e to 6eaf31c Compare July 31, 2026 23:27
Now the type system ensures that Timer::Enabled
never stores 0 value inside accidentally,
it is impossible to put 0 there without unsafe code.
@link2xt
link2xt force-pushed the link2xt/ephemeral-timer-duration-nonzero branch from 6eaf31c to e2d9d1c Compare July 31, 2026 23:28
@link2xt
link2xt enabled auto-merge (rebase) July 31, 2026 23:30
@link2xt
link2xt merged commit 62d3f38 into main Jul 31, 2026
54 of 55 checks passed
@link2xt
link2xt deleted the link2xt/ephemeral-timer-duration-nonzero branch July 31, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants