Skip to content

Commit

Permalink
Add one BILLION derives
Browse files Browse the repository at this point in the history
  • Loading branch information
bitfl0wer committed Jul 18, 2024
1 parent b0667a3 commit 491cd25
Show file tree
Hide file tree
Showing 75 changed files with 961 additions and 562 deletions.
2 changes: 1 addition & 1 deletion src/api/channels/reactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};

/// Useful metadata for working with [`types::Reaction`], bundled together nicely.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash, PartialOrd, Ord)]
pub struct ReactionMeta {
pub message_id: types::Snowflake,
pub channel_id: types::Snowflake,
Expand Down
2 changes: 1 addition & 1 deletion src/gateway/backends/tungstenite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio_tungstenite::{

use crate::gateway::{GatewayMessage, RawGatewayMessage};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy)]
pub struct TungsteniteBackend;

// These could be made into inherent associated types when that's stabilized
Expand Down
2 changes: 1 addition & 1 deletion src/gateway/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl GatewayHandle {

/// Sends a call sync to the server
pub async fn send_call_sync(&self, to_send: types::CallSync) {
let to_send_value = serde_json::to_value(&to_send).unwrap();
let to_send_value = serde_json::to_value(to_send).unwrap();

trace!("GW: Sending Call Sync..");

Expand Down
3 changes: 1 addition & 2 deletions src/gateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use async_trait::async_trait;

pub mod backends;
pub mod events;
Expand All @@ -20,7 +19,7 @@ pub use message::*;
pub use options::*;

use crate::errors::GatewayError;
use crate::types::{Snowflake, WebSocketEvent};
use crate::types::{Snowflake};

use std::any::Any;
use std::collections::HashMap;
Expand Down
34 changes: 16 additions & 18 deletions src/gateway/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Debug, Default)]
#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Debug, Default, Copy)]
/// Options passed when initializing the gateway connection.
///
/// E.g. compression
Expand All @@ -17,20 +17,19 @@
///
/// See <https://docs.discord.sex/topics/gateway#connections>
pub struct GatewayOptions {
pub encoding: GatewayEncoding,
pub transport_compression: GatewayTransportCompression,
pub encoding: GatewayEncoding,
pub transport_compression: GatewayTransportCompression,
}

impl GatewayOptions {
/// Adds the options to an existing gateway url
///
/// Returns the new url
pub(crate) fn add_to_url(&self, url: String) -> String {

let mut url = url;

let mut parameters = Vec::with_capacity(2);

let encoding = self.encoding.to_url_parameter();
parameters.push(encoding);

Expand All @@ -54,8 +53,7 @@ impl GatewayOptions {
if !has_parameters {
url = format!("{}?{}", url, parameter);
has_parameters = true;
}
else {
} else {
url = format!("{}&{}", url, parameter);
}
}
Expand All @@ -78,15 +76,15 @@ pub enum GatewayTransportCompression {

impl GatewayTransportCompression {
/// Returns the option as a url parameter.
///
///
/// If set to [GatewayTransportCompression::None] returns [None].
///
/// If set to anything else, returns a string like "compress=zlib-stream"
pub(crate) fn to_url_parameter(self) -> Option<String> {
match self {
Self::None => None,
Self::ZLibStream => Some(String::from("compress=zlib-stream"))
}
match self {
Self::None => None,
Self::ZLibStream => Some(String::from("compress=zlib-stream")),
}
}
}

Expand All @@ -102,17 +100,17 @@ pub enum GatewayEncoding {
/// Should be lighter and faster than json.
///
/// !! Chorus does not implement ETF yet !!
ETF
ETF,
}

impl GatewayEncoding {
/// Returns the option as a url parameter.
///
///
/// Returns a string like "encoding=json"
pub(crate) fn to_url_parameter(self) -> String {
match self {
Self::Json => String::from("encoding=json"),
Self::ETF => String::from("encoding=etf")
}
match self {
Self::Json => String::from("encoding=json"),
Self::ETF => String::from("encoding=etf"),
}
}
}
27 changes: 1 addition & 26 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ pub struct Instance {
pub gateway_options: GatewayOptions,
}

impl PartialEq for Instance {
fn eq(&self, other: &Self) -> bool {
self.urls == other.urls
&& self.instance_info == other.instance_info
&& self.limits_information == other.limits_information
}
}

impl std::hash::Hash for Instance {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.urls.hash(state);
self.instance_info.hash(state);
if let Some(inf) = &self.limits_information {
inf.hash(state);
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq)]
pub struct LimitsInformation {
pub ratelimits: HashMap<LimitType, Limit>,
Expand All @@ -69,6 +51,7 @@ impl std::hash::Hash for LimitsInformation {
}
}

#[cfg(not(tarpaulin_include))]
impl PartialEq for LimitsInformation {
fn eq(&self, other: &Self) -> bool {
self.ratelimits.iter().eq(other.ratelimits.iter())
Expand Down Expand Up @@ -175,14 +158,6 @@ pub struct ChorusUser {
pub gateway: GatewayHandle,
}

impl PartialEq for ChorusUser {
fn eq(&self, other: &Self) -> bool {
self.token == other.token
&& self.limits == other.limits
&& self.gateway.url == other.gateway.url
}
}

impl ChorusUser {
pub fn token(&self) -> String {
self.token.clone()
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read
)]
#![allow(clippy::module_inception)]
#![deny(
missing_debug_implementations,
clippy::extra_unused_lifetimes,
clippy::from_over_into,
clippy::needless_borrow,
Expand All @@ -110,7 +109,9 @@ This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read
clippy::unimplemented,
clippy::dbg_macro,
clippy::print_stdout,
clippy::print_stderr
clippy::print_stderr,
missing_debug_implementations,
missing_copy_implementations
)]
#[cfg(all(feature = "rt", feature = "rt_multi_thread"))]
compile_error!("feature \"rt\" and feature \"rt_multi_thread\" cannot be enabled at the same time");
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/defaults_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use crate::types::config::types::subconfigs::defaults::{guild::GuildDefaults, user::UserDefaults};

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Copy)]
#[serde(rename_all = "camelCase")]
pub struct DefaultsConfiguration {
pub guild: GuildDefaults,
Expand Down
4 changes: 3 additions & 1 deletion src/types/config/types/login_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(
Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Copy, Hash, PartialOrd, Ord,
)]
#[serde(rename_all = "camelCase")]
pub struct LoginConfiguration {
pub require_captcha: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/metrics_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Ord, PartialOrd, Copy, Hash)]
#[serde(rename_all = "camelCase")]
pub struct MetricsConfiguration {
pub timeout: u64,
Expand Down
4 changes: 3 additions & 1 deletion src/types/config/types/password_reset_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(
Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Copy, Hash, PartialOrd, Ord,
)]
#[serde(rename_all = "camelCase")]
pub struct PasswordResetConfiguration {
pub require_captcha: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/defaults/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use crate::types::{ExplicitContentFilterLevel, MessageNotificationLevel};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, Hash, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub struct GuildDefaults {
pub max_presences: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/defaults/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, Hash, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub struct UserDefaults {
pub premium: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/guild/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord, Hash)]
#[serde(rename_all = "camelCase")]
pub struct DiscoverConfiguration {
pub show_all_guilds: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/limits/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub struct ChannelLimits {
pub max_pins: u16,
Expand Down
4 changes: 2 additions & 2 deletions src/types/config/types/subconfigs/limits/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord, Hash)]
pub struct GlobalRateLimit {
pub limit: u16,
pub window: u64,
Expand All @@ -21,7 +21,7 @@ impl Default for GlobalRateLimit {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord, Hash)]
#[serde(rename_all = "camelCase")]
pub struct GlobalRateLimits {
pub register: GlobalRateLimit,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/limits/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, Hash, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub struct GuildLimits {
pub max_roles: u16,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/limits/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord, Hash)]
#[serde(rename_all = "camelCase")]
pub struct MessageLimits {
pub max_characters: u32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};

use crate::types::config::types::subconfigs::limits::ratelimits::RateLimitOptions;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord, Hash)]
pub struct AuthRateLimit {
pub login: RateLimitOptions,
pub register: RateLimitOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/limits/ratelimits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
pub mod auth;
pub mod route;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, PartialOrd, Ord, Copy)]
#[serde(rename_all = "camelCase")]
pub struct RateLimitOptions {
pub bot: Option<u64>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::types::config::types::subconfigs::limits::ratelimits::{
auth::AuthRateLimit, RateLimitOptions,
};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, Copy, PartialOrd, Ord)]
pub struct RouteRateLimit {
pub guild: RateLimitOptions,
pub webhook: RateLimitOptions,
Expand Down
16 changes: 8 additions & 8 deletions src/types/config/types/subconfigs/limits/rates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ impl Default for RateLimits {
impl RateLimits {
pub fn to_hash_map(&self) -> HashMap<LimitType, RateLimitOptions> {
let mut map = HashMap::new();
map.insert(LimitType::AuthLogin, self.routes.auth.login.clone());
map.insert(LimitType::AuthRegister, self.routes.auth.register.clone());
map.insert(LimitType::ChannelBaseline, self.routes.channel.clone());
map.insert(LimitType::Error, self.error.clone());
map.insert(LimitType::Global, self.global.clone());
map.insert(LimitType::Ip, self.ip.clone());
map.insert(LimitType::WebhookBaseline, self.routes.webhook.clone());
map.insert(LimitType::GuildBaseline, self.routes.guild.clone());
map.insert(LimitType::AuthLogin, self.routes.auth.login);
map.insert(LimitType::AuthRegister, self.routes.auth.register);
map.insert(LimitType::ChannelBaseline, self.routes.channel);
map.insert(LimitType::Error, self.error);
map.insert(LimitType::Global, self.global);
map.insert(LimitType::Ip, self.ip);
map.insert(LimitType::WebhookBaseline, self.routes.webhook);
map.insert(LimitType::GuildBaseline, self.routes.guild);
map
}
}
2 changes: 1 addition & 1 deletion src/types/config/types/subconfigs/limits/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord, Copy, Hash)]
#[serde(rename_all = "camelCase")]
pub struct UserLimits {
pub max_guilds: u64,
Expand Down
4 changes: 2 additions & 2 deletions src/types/config/types/subconfigs/region/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, PartialOrd, Copy)]
pub struct LatLong {
pub latitude: f64,
pub longitude: f64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, PartialOrd)]
pub struct Region {
pub id: String,
pub name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy, PartialOrd, Ord, Hash)]
pub struct DateOfBirthConfiguration {
pub required: bool,
pub minimum: u8,
Expand Down
Loading

0 comments on commit 491cd25

Please sign in to comment.