Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ coherence_leak_check = "deny"
confusable_idents = "deny"
const_evaluatable_unchecked = "deny"
const_item_mutation = "deny"
dangling_pointers_from_temporaries = "deny"
dead_code = "deny"
deprecated = "deny"
deprecated_where_clause_location = "deny"
Expand Down Expand Up @@ -130,13 +131,11 @@ semicolon_in_expressions_from_macros = "deny"
special_module_name = "deny"
stable_features = "deny"
suspicious_double_ref_op = "deny"
temporary_cstring_as_ptr = "deny"
trivial_bounds = "deny"
type_alias_bounds = "deny"
tyvar_behind_raw_pointer = "deny"
uncommon_codepoints = "deny"
unconditional_recursion = "deny"
undefined_naked_function_abi = "deny"
unexpected_cfgs = "deny"
ungated_async_fn_track_caller = "deny"
uninhabited_static = "deny"
Expand Down
3 changes: 1 addition & 2 deletions caracal-daemon/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ mod tests {

#[test]
fn test_command_simple() {
if let Some(Commands::Version { .. }) =
Cli::parse_from(["program_name", "version"]).commands
if matches!(Cli::parse_from(["program_name", "version"]).commands, Some(Commands::Version))
{
// everything is good.
} else {
Expand Down
5 changes: 2 additions & 3 deletions caracal-tui/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Default for Cli {
}

impl Cli {
#[allow(clippy::too_many_lines)]
#[allow(clippy::result_large_err, clippy::too_many_lines)]
pub fn run(self) -> Result<(), Error> {
let Self { commands, log_level, config_file } = self;

Expand Down Expand Up @@ -105,8 +105,7 @@ mod tests {

#[test]
fn test_command_simple() {
if let Some(Commands::Version { .. }) =
Cli::parse_from(["program_name", "version"]).commands
if matches!(Cli::parse_from(["program_name", "version"]).commands, Some(Commands::Version))
{
// everything is good.
} else {
Expand Down
2 changes: 1 addition & 1 deletion caracal-tui/src/tui/state_store/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ impl State {

pub fn mark_disconnected(&mut self) { self.daemon_version = None; }

pub fn tick_timer(&mut self) { self.timer += 1; }
pub const fn tick_timer(&mut self) { self.timer += 1; }
}
1 change: 1 addition & 0 deletions caracal-tui/src/tui/state_store/state_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl StateStore {
(Self { state_tx, server_endpoint, access_token }, state_rx)
}

#[allow(clippy::cognitive_complexity)]
pub async fn serve(
self,
mut action_rx: mpsc::UnboundedReceiver<Action>,
Expand Down
2 changes: 2 additions & 0 deletions caracal-tui/src/tui/ui/components/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub trait Component {
where
Self: Sized;

// FIXME: Use this method or remove it.
#[allow(dead_code)]
fn name(&self) -> &str;

fn handle_key_event(&mut self, key: KeyEvent);
Expand Down
2 changes: 2 additions & 0 deletions caracal-tui/src/tui/ui/pages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct AppRouter {
}

impl AppRouter {
// FIXME: Use this method or remove it.
#[allow(dead_code)]
fn get_active_page_component(&self) -> &dyn Component {
match self.props.active_page {
ActivePage::StatusPage => &self.status_page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Component for InformationArea {
Self { props: Props::from(state) }
}

fn name(&self) -> &str { "Information" }
fn name(&self) -> &'static str { "Information" }

fn handle_key_event(&mut self, _key: KeyEvent) {}
}
Expand Down
4 changes: 2 additions & 2 deletions caracal-tui/src/tui/ui/pages/status/components/task_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Component for TaskStatusList {
Self { props: Props::from(state), ..self }
}

fn name(&self) -> &str { "Task Status List" }
fn name(&self) -> &'static str { "Task Status List" }

fn handle_key_event(&mut self, key: KeyEvent) {
if key.kind != KeyEventKind::Press {
Expand Down Expand Up @@ -206,7 +206,7 @@ impl ComponentRender<RenderProps> for TaskStatusList {
Cell::from(status.file_path.file_name().unwrap_or_default().to_string_lossy()),
Cell::new(humansize::format_size(total_bytes, humansize::BINARY)),
Cell::new(humansize::format_size(
if received_bytes >= total_bytes { 0 } else { total_bytes - received_bytes },
total_bytes.saturating_sub(received_bytes),
humansize::BINARY,
)),
Cell::new(progress_percentage),
Expand Down
2 changes: 1 addition & 1 deletion caracal-tui/src/tui/ui/pages/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Component for StatusPage {
}
}

fn name(&self) -> &str { "Status Page" }
fn name(&self) -> &'static str { "Status Page" }

fn handle_key_event(&mut self, key: KeyEvent) {
if key.kind != KeyEventKind::Press {
Expand Down
5 changes: 2 additions & 3 deletions caracal/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Default for Cli {
}

impl Cli {
#[allow(clippy::too_many_lines)]
#[allow(clippy::too_many_lines, clippy::result_large_err)]
pub fn run(self) -> Result<(), Error> {
let Self {
commands,
Expand Down Expand Up @@ -368,8 +368,7 @@ mod tests {

#[test]
fn test_command_simple() {
if let Some(Commands::Version { .. }) =
Cli::parse_from(["program_name", "version"]).commands
if matches!(Cli::parse_from(["program_name", "version"]).commands, Some(Commands::Version))
{
// everything is good.
} else {
Expand Down
2 changes: 1 addition & 1 deletion caracal/src/cli/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn build_table() -> Table {

if let Some(width) = table.width() {
let _ = table.set_width(width - 10);
};
}

table
}
1 change: 0 additions & 1 deletion crates/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ http = "1"

bytes = "1"
directories = "6"
lazy_static = "1"
mime = "0.3"
semver = "1"
snafu = "0.8"
Expand Down
38 changes: 19 additions & 19 deletions crates/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub mod utils;
use std::{
net::{IpAddr, Ipv4Addr},
path::PathBuf,
sync::LazyLock,
};

use directories::ProjectDirs;
use lazy_static::lazy_static;

pub const PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");

Expand All @@ -24,18 +24,18 @@ pub const DBUS_MANAGER_OBJECT_PATH: &str = "/org/caracal/caracal-daemon/manager"

pub const FALLBACK_FILENAME: &str = "index.html";

lazy_static! {
pub static ref PROJECT_SEMVER: semver::Version = semver::Version::parse(PROJECT_VERSION)
.unwrap_or(semver::Version {
major: 0,
minor: 0,
patch: 0,
pre: semver::Prerelease::EMPTY,
build: semver::BuildMetadata::EMPTY
});
pub static ref DEFAULT_HTTP_USER_AGENT: String =
format!("{PROJECT_NAME_WITH_INITIAL_CAPITAL}/{PROJECT_VERSION}");
}
pub static PROJECT_SEMVER: LazyLock<semver::Version> = LazyLock::new(|| {
semver::Version::parse(PROJECT_VERSION).unwrap_or(semver::Version {
major: 0,
minor: 0,
patch: 0,
pre: semver::Prerelease::EMPTY,
build: semver::BuildMetadata::EMPTY,
})
});

pub static DEFAULT_HTTP_USER_AGENT: LazyLock<String> =
LazyLock::new(|| format!("{PROJECT_NAME_WITH_INITIAL_CAPITAL}/{PROJECT_VERSION}"));

pub const PROJECT_NAME: &str = "caracal";
pub const PROJECT_NAME_WITH_INITIAL_CAPITAL: &str = "Caracal";
Expand All @@ -60,9 +60,9 @@ pub const DEFAULT_WEB_HOST: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);
pub const DEFAULT_METRICS_PORT: u16 = 37002;
pub const DEFAULT_METRICS_HOST: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);

lazy_static::lazy_static! {
pub static ref PROJECT_CONFIG_DIR: PathBuf = ProjectDirs::from("", PROJECT_NAME, PROJECT_NAME)
.expect("Creating `ProjectDirs` should always success")
.config_dir()
.to_path_buf();
}
pub static PROJECT_CONFIG_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
ProjectDirs::from("", PROJECT_NAME, PROJECT_NAME)
.expect("Creating `ProjectDirs` should always success")
.config_dir()
.to_path_buf()
});
6 changes: 1 addition & 5 deletions crates/base/src/model/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ impl ProgressChunk {
#[must_use]
pub const fn remaining(&self) -> u64 {
let len = self.len();
if len >= self.received {
len - self.received
} else {
0
}
len.saturating_sub(self.received)
}

#[must_use]
Expand Down
2 changes: 1 addition & 1 deletion crates/base/src/utils/retry_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RetryInterval {
self
}

pub fn reset(&mut self) { self.count = 0; }
pub const fn reset(&mut self) { self.count = 0; }

#[must_use]
pub const fn limit(&self) -> usize { self.limit }
Expand Down
10 changes: 3 additions & 7 deletions crates/engine/src/downloader/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ impl Chunk {

pub const fn remaining(&self) -> u64 {
let len = self.len();
if len >= self.received {
len - self.received
} else {
0
}
len.saturating_sub(self.received)
}

pub fn split(&mut self) -> Option<Self> {
pub const fn split(&mut self) -> Option<Self> {
if self.received >= self.len() || self.is_completed {
None
} else {
Expand All @@ -45,7 +41,7 @@ impl Chunk {
}
}

pub fn freeze(&mut self) -> Option<Self> {
pub const fn freeze(&mut self) -> Option<Self> {
if self.received == 0 {
None
} else {
Expand Down
3 changes: 3 additions & 0 deletions crates/engine/src/downloader/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct Builder {

impl Builder {
/// # Errors
#[allow(clippy::result_large_err)]
pub fn new() -> Result<Self, Error> {
Ok(Self {
default_concurrent_number: 5,
Expand Down Expand Up @@ -95,6 +96,7 @@ impl Builder {
self
}

#[allow(clippy::result_large_err)]
pub fn build(self) -> Result<Factory, Error> {
let Self {
http_user_agent,
Expand Down Expand Up @@ -146,6 +148,7 @@ pub struct Factory {
impl Factory {
/// # Errors
#[inline]
#[allow(clippy::result_large_err)]
pub fn builder() -> Result<Builder, Error> { Builder::new() }

/// # Errors
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/downloader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Downloader {
Ok(summary)
}

#[allow(clippy::too_many_lines)]
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
async fn serve_with_multiple_workers(
ServeWithMultipleWorkerOptions {
worker_number,
Expand Down
8 changes: 2 additions & 6 deletions crates/engine/src/downloader/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl DownloaderStatus {
pub fn chunks(&self) -> Vec<model::ProgressChunk> { self.chunks.clone() }

#[must_use]
pub fn total_chunk_count(&self) -> usize { self.chunks.len() }
pub const fn total_chunk_count(&self) -> usize { self.chunks.len() }

#[must_use]
pub fn completed_chunk_count(&self) -> usize {
Expand All @@ -53,11 +53,7 @@ impl DownloaderStatus {
#[must_use]
pub fn remaining(&self) -> u64 {
let total_received = self.total_received();
if self.content_length < total_received {
0
} else {
self.content_length - total_received
}
self.content_length.saturating_sub(total_received)
}

#[inline]
Expand Down
10 changes: 4 additions & 6 deletions crates/engine/src/downloader/transfer_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct TransferStatus {
}

impl TransferStatus {
#[allow(clippy::result_large_err)]
pub fn new(content_length: u64, chunk_size: u64) -> Result<Self, Error> {
let chunks = InitialChunks::new(0, content_length - 1, chunk_size)?
.map(|chunk| (chunk.start, chunk))
Expand Down Expand Up @@ -47,11 +48,7 @@ impl TransferStatus {

pub fn remaining(&self) -> u64 {
let total_received = self.total_received();
if self.content_length < total_received {
0
} else {
self.content_length - total_received
}
self.content_length.saturating_sub(total_received)
}

pub fn split(&mut self) -> Option<(Chunk, Chunk)> {
Expand Down Expand Up @@ -99,7 +96,7 @@ impl TransferStatus {
#[must_use]
pub const fn concurrent_number(&self) -> usize { self.concurrent_number }

pub fn update_concurrent_number(&mut self, concurrent_number: usize) {
pub const fn update_concurrent_number(&mut self, concurrent_number: usize) {
self.concurrent_number = concurrent_number;
}
}
Expand All @@ -117,6 +114,7 @@ impl InitialChunks {
/// * `start` - the first byte of the file, typically 0
/// * `end` - the highest value in bytes, typically content-length - 1
/// * `chunk_size` - the desired size of the chunks
#[allow(clippy::result_large_err)]
pub const fn new(start: u64, end: u64, chunk_size: u64) -> Result<Self, Error> {
if chunk_size == 0 {
return Err(Error::BadChunkSize { value: chunk_size });
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use snafu::Snafu;

pub type Result<T> = std::result::Result<T, Error>;

#[allow(clippy::result_large_err)]
#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
pub enum Error {
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/fetcher/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Fetcher {
}

impl Fetcher {
#[allow(clippy::cognitive_complexity)]
pub async fn new(client: reqwest::Client, uri: http::Uri) -> Result<Self> {
let resp =
client.head(uri.to_string()).send().await.context(error::FetchHttpHeaderSnafu)?;
Expand Down
Loading
Loading