fix!: remove possible panic from client builder
fix: simplify integer divisions
This commit is contained in:
parent
182f9ebfb8
commit
32b4800b46
9 changed files with 40 additions and 21 deletions
|
|
@ -272,6 +272,17 @@ pub fn sanitize_yt_url(url: &str) -> String {
|
|||
sanitize_yt_url_inner(url).unwrap_or_else(|| url.to_string())
|
||||
}
|
||||
|
||||
pub fn div_ceil(a: u32, b: u32) -> u32 {
|
||||
let d = a / b;
|
||||
let r = a % b;
|
||||
|
||||
if r > 0 && b > 0 {
|
||||
d + 1
|
||||
} else {
|
||||
d
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TryRemove<T> {
|
||||
/// Removes and returns the element at position `index` within the vector,
|
||||
/// shifting all elements after it to the left.
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ pub enum DateCmp {
|
|||
}
|
||||
|
||||
impl TimeUnit {
|
||||
pub fn secs(self) -> i64 {
|
||||
pub fn secs(self) -> u32 {
|
||||
match self {
|
||||
TimeUnit::Second => 1,
|
||||
TimeUnit::Minute => 60,
|
||||
|
|
@ -91,8 +91,8 @@ impl TimeUnit {
|
|||
}
|
||||
|
||||
impl TimeAgo {
|
||||
fn secs(self) -> i64 {
|
||||
i64::from(self.n) * self.unit.secs()
|
||||
fn secs(self) -> u32 {
|
||||
u32::from(self.n) * self.unit.secs()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ impl Mul<u8> for TimeAgo {
|
|||
|
||||
impl From<TimeAgo> for Duration {
|
||||
fn from(ta: TimeAgo) -> Self {
|
||||
Duration::seconds(ta.secs())
|
||||
Duration::seconds(ta.secs().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -331,7 +331,7 @@ pub fn parse_video_duration(lang: Language, video_duration: &str) -> Option<u32>
|
|||
tokens.peek()?;
|
||||
|
||||
tokens.for_each(|ta| {
|
||||
secs += n * ta.secs() as u32;
|
||||
secs += n * ta.secs();
|
||||
n = 1;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue