Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,24 @@ impl fmt::Display for LifecycleId {
}
}

impl LifecycleId {
/// Creates a new `LifecycleId`.
///
/// Returns `None` if the value is zero, as zero is not a valid lifecycle identifier.
pub fn new(n: u64) -> Option<LifecycleId> {
NonZeroU64::new(n).map(LifecycleId)
}

impl From<u64> for LifecycleId {
/// Creates a new `LifecycleId` from a non-zero value.
///
/// # Panics
///
/// Panics if `n` is zero.
pub fn from(n: u64) -> LifecycleId {
fn from(n: u64) -> Self {
debug_assert!(n != 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.

I changed my mind, I don't think this is idiomatic. I'll come up with something else to unify these two constructors.

LifecycleId(NonZeroU64::new(n).unwrap())
Self(NonZeroU64::new(n).expect("LifecycleId cannot be zero"))
}
}

impl LifecycleId {
/// Creates a new `LifecycleId`.
///
/// Returns `None` if the value is zero, as zero is not a valid lifecycle identifier.
pub fn new(n: u64) -> Option<LifecycleId> {
NonZeroU64::new(n).map(LifecycleId)
}

/// Returns the underlying value.
Expand Down
Loading