about summary refs log tree commit diff stats
path: root/yt/src/select/selection_file/duration.rs
diff options
context:
space:
mode:
Diffstat (limited to 'yt/src/select/selection_file/duration.rs')
-rw-r--r--yt/src/select/selection_file/duration.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/yt/src/select/selection_file/duration.rs b/yt/src/select/selection_file/duration.rs
index a38981c..3957f0f 100644
--- a/yt/src/select/selection_file/duration.rs
+++ b/yt/src/select/selection_file/duration.rs
@@ -12,6 +12,8 @@ use std::str::FromStr;
 
 use anyhow::{Context, Result};
 
+use crate::unreachable::Unreachable;
+
 #[derive(Copy, Clone, Debug)]
 pub struct Duration {
     time: u32,
@@ -23,11 +25,9 @@ impl FromStr for Duration {
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         fn parse_num(str: &str, suffix: char) -> Result<u32> {
             str.strip_suffix(suffix)
-                .with_context(|| {
-                    format!("Failed to strip suffix '{}' of number: '{}'", suffix, str)
-                })?
+                .with_context(|| format!("Failed to strip suffix '{suffix}' of number: '{str}'"))?
                 .parse::<u32>()
-                .with_context(|| format!("Failed to parse '{}'", suffix))
+                .with_context(|| format!("Failed to parse '{suffix}'"))
         }
 
         if s == "[No Duration]" {
@@ -66,7 +66,9 @@ impl FromStr for Duration {
 impl From<Option<f64>> for Duration {
     fn from(value: Option<f64>) -> Self {
         Self {
-            time: value.unwrap_or(0.0).ceil() as u32,
+            #[allow(clippy::cast_possible_truncation)]
+            time: u32::try_from(value.unwrap_or(0.0).ceil() as i128)
+                .unreachable("This should not exceed `u32::MAX`"),
         }
     }
 }