Skip to content

Commit

Permalink
refactor: [#932] sort config core section fields
Browse files Browse the repository at this point in the history
When you format a toml file with a linter it sorts the keys
alphabetically. It's good to have the same order in the code.

It's also a common practice for JSON. This helps to make serialization
deterministic.
  • Loading branch information
josecelano committed Jul 1, 2024
1 parent 5f1fdbd commit 2186809
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions packages/configuration/src/v1/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@ use crate::{AnnouncePolicy, TrackerPolicy};
#[allow(clippy::struct_excessive_bools)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct Core {
/// Tracker mode. See [`TrackerMode`] for more information.
#[serde(default = "Core::default_mode")]
pub mode: TrackerMode,

/// Weather the tracker should collect statistics about tracker usage.
/// If enabled, the tracker will collect statistics like the number of
/// connections handled, the number of announce requests handled, etc.
/// Refer to the [`Tracker`](https://docs.rs/torrust-tracker) for more
/// information about the collected metrics.
#[serde(default = "Core::default_tracker_usage_statistics")]
pub tracker_usage_statistics: bool,

/// Interval in seconds that the cleanup job will run to remove inactive
/// peers from the torrent peer list.
#[serde(default = "Core::default_inactive_peer_cleanup_interval")]
pub inactive_peer_cleanup_interval: u64,

// Tracker policy configuration.
#[serde(default = "Core::default_tracker_policy")]
pub tracker_policy: TrackerPolicy,

// Announce policy configuration.
#[serde(default = "Core::default_announce_policy")]
pub announce_policy: AnnouncePolicy,
Expand All @@ -37,51 +16,71 @@ pub struct Core {
#[serde(default = "Core::default_database")]
pub database: Database,

/// Interval in seconds that the cleanup job will run to remove inactive
/// peers from the torrent peer list.
#[serde(default = "Core::default_inactive_peer_cleanup_interval")]
pub inactive_peer_cleanup_interval: u64,

/// Tracker mode. See [`TrackerMode`] for more information.
#[serde(default = "Core::default_mode")]
pub mode: TrackerMode,

// Network configuration.
#[serde(default = "Core::default_network")]
pub net: Network,

// Tracker policy configuration.
#[serde(default = "Core::default_tracker_policy")]
pub tracker_policy: TrackerPolicy,

/// Weather the tracker should collect statistics about tracker usage.
/// If enabled, the tracker will collect statistics like the number of
/// connections handled, the number of announce requests handled, etc.
/// Refer to the [`Tracker`](https://docs.rs/torrust-tracker) for more
/// information about the collected metrics.
#[serde(default = "Core::default_tracker_usage_statistics")]
pub tracker_usage_statistics: bool,
}

impl Default for Core {
fn default() -> Self {
Self {
mode: Self::default_mode(),
tracker_usage_statistics: Self::default_tracker_usage_statistics(),
inactive_peer_cleanup_interval: Self::default_inactive_peer_cleanup_interval(),
tracker_policy: Self::default_tracker_policy(),
announce_policy: Self::default_announce_policy(),
database: Self::default_database(),
inactive_peer_cleanup_interval: Self::default_inactive_peer_cleanup_interval(),
mode: Self::default_mode(),
net: Self::default_network(),
tracker_policy: Self::default_tracker_policy(),
tracker_usage_statistics: Self::default_tracker_usage_statistics(),
}
}
}

impl Core {
fn default_mode() -> TrackerMode {
TrackerMode::Public
fn default_announce_policy() -> AnnouncePolicy {
AnnouncePolicy::default()
}

fn default_tracker_usage_statistics() -> bool {
true
fn default_database() -> Database {
Database::default()
}

fn default_inactive_peer_cleanup_interval() -> u64 {
600
}

fn default_tracker_policy() -> TrackerPolicy {
TrackerPolicy::default()
fn default_mode() -> TrackerMode {
TrackerMode::Public
}

fn default_announce_policy() -> AnnouncePolicy {
AnnouncePolicy::default()
fn default_network() -> Network {
Network::default()
}

fn default_database() -> Database {
Database::default()
fn default_tracker_policy() -> TrackerPolicy {
TrackerPolicy::default()
}

fn default_network() -> Network {
Network::default()
fn default_tracker_usage_statistics() -> bool {
true
}
}

0 comments on commit 2186809

Please sign in to comment.