diff --git a/src/api/mod.rs b/src/api/mod.rs index e3c7216..8bc1c94 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -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 { - NonZeroU64::new(n).map(LifecycleId) - } - +impl From 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); - 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 { + NonZeroU64::new(n).map(LifecycleId) } /// Returns the underlying value.