fix!: remove possible panic from client builder

fix: simplify integer divisions
This commit is contained in:
ThetaDev 2023-05-31 12:14:11 +02:00
parent 182f9ebfb8
commit 32b4800b46
9 changed files with 40 additions and 21 deletions

View file

@ -446,8 +446,7 @@ impl RustyPipeBuilder {
}
/// Return a new, configured RustyPipe instance.
#[must_use]
pub fn build(self) -> RustyPipe {
pub fn build(self) -> Result<RustyPipe, Error> {
let mut client_builder = ClientBuilder::new()
.user_agent(self.user_agent.unwrap_or_else(|| DEFAULT_UA.to_owned()))
.gzip(true)
@ -458,7 +457,7 @@ impl RustyPipeBuilder {
client_builder = client_builder.timeout(timeout);
}
let http = client_builder.build().unwrap();
let http = client_builder.build()?;
let storage_dir = self.storage_dir.unwrap_or_default();
@ -480,7 +479,7 @@ impl RustyPipeBuilder {
})
.unwrap_or_default();
RustyPipe {
Ok(RustyPipe {
inner: Arc::new(RustyPipeRef {
http,
storage,
@ -503,7 +502,7 @@ impl RustyPipeBuilder {
},
default_opts: self.default_opts,
}),
}
})
}
/// Set the default directory to store the cachefile and reports.
@ -687,8 +686,9 @@ impl RustyPipe {
///
/// To create an instance with custom options, use [`RustyPipeBuilder`] instead.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn new() -> Self {
RustyPipeBuilder::new().build()
RustyPipeBuilder::new().build().unwrap()
}
/// Create a new [`RustyPipeBuilder`]

View file

@ -342,9 +342,8 @@ impl MapResponse<VideoPlayer> for response::Player {
+ "&sigh="
+ sigh;
let sprite_count = (f64::from(total_count)
/ f64::from(frames_per_page_x * frames_per_page_y))
.ceil() as u32;
let sprite_count =
util::div_ceil(total_count, frames_per_page_x * frames_per_page_y);
Some(Frameset {
url_template: url,