lints, warnings, errors

This commit is contained in:
kozabrada123 2024-06-23 16:04:41 +02:00
parent f290b84d11
commit 3d1c275f48
9 changed files with 39 additions and 41 deletions

View File

@ -9,7 +9,7 @@ use futures_util::{
use ws_stream_wasm::*; use ws_stream_wasm::*;
use crate::gateway::GatewayMessage; use crate::gateway::{GatewayMessage, RawGatewayMessage};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct WasmBackend; pub struct WasmBackend;
@ -46,3 +46,21 @@ impl From<WsMessage> for GatewayMessage {
} }
} }
} }
impl From<RawGatewayMessage> for WsMessage {
fn from(message: RawGatewayMessage) -> Self {
match message {
RawGatewayMessage::Text(text) => tungstenite::Message::Text(text),
RawGatewayMessage::Bytes(bytes) => tungstenite::Message::Binary(bytes),
}
}
}
impl From<WsMessage> for RawGatewayMessage {
fn from(value: WsMessage) -> Self {
match value {
WsMessage::Binary(bytes) => RawGatewayMessage::Bytes(bytes),
WsMessage::Text(text) => RawGatewayMessage::Text(text),
}
}
}

View File

@ -217,7 +217,7 @@ impl Gateway {
message = GatewayMessage::from_raw_json_message(raw_message).unwrap() message = GatewayMessage::from_raw_json_message(raw_message).unwrap()
} }
GatewayTransportCompression::ZLibStream => { GatewayTransportCompression::ZLibStream => {
let message_bytes = raw_message.to_bytes(); let message_bytes = raw_message.into_bytes();
let can_decompress = message_bytes.len() > 4 let can_decompress = message_bytes.len() > 4
&& message_bytes[message_bytes.len() - 4..] == ZLIB_SUFFIX; && message_bytes[message_bytes.len() - 4..] == ZLIB_SUFFIX;

View File

@ -19,7 +19,7 @@ pub(crate) enum RawGatewayMessage {
impl RawGatewayMessage { impl RawGatewayMessage {
/// Attempt to consume the message into a String, will try to convert binary to utf8 /// Attempt to consume the message into a String, will try to convert binary to utf8
pub fn to_text(self) -> Result<String, FromUtf8Error> { pub fn into_text(self) -> Result<String, FromUtf8Error> {
match self { match self {
RawGatewayMessage::Text(text) => Ok(text), RawGatewayMessage::Text(text) => Ok(text),
RawGatewayMessage::Bytes(bytes) => String::from_utf8(bytes), RawGatewayMessage::Bytes(bytes) => String::from_utf8(bytes),
@ -27,7 +27,7 @@ impl RawGatewayMessage {
} }
/// Consume the message into bytes, will convert text to binary /// Consume the message into bytes, will convert text to binary
pub fn to_bytes(self) -> Vec<u8> { pub fn into_bytes(self) -> Vec<u8> {
match self { match self {
RawGatewayMessage::Text(text) => text.as_bytes().to_vec(), RawGatewayMessage::Text(text) => text.as_bytes().to_vec(),
RawGatewayMessage::Bytes(bytes) => bytes, RawGatewayMessage::Bytes(bytes) => bytes,
@ -79,7 +79,7 @@ impl GatewayMessage {
pub(crate) fn from_raw_json_message( pub(crate) fn from_raw_json_message(
message: RawGatewayMessage, message: RawGatewayMessage,
) -> Result<GatewayMessage, FromUtf8Error> { ) -> Result<GatewayMessage, FromUtf8Error> {
let text = message.to_text()?; let text = message.into_text()?;
Ok(GatewayMessage(text)) Ok(GatewayMessage(text))
} }
@ -105,6 +105,6 @@ impl GatewayMessage {
message: RawGatewayMessage, message: RawGatewayMessage,
inflate: &mut flate2::Decompress, inflate: &mut flate2::Decompress,
) -> Result<GatewayMessage, std::io::Error> { ) -> Result<GatewayMessage, std::io::Error> {
Self::from_zlib_stream_json_bytes(&message.to_bytes(), inflate) Self::from_zlib_stream_json_bytes(&message.into_bytes(), inflate)
} }
} }

View File

@ -39,9 +39,9 @@ impl GatewayOptions {
parameters.push(some_compression); parameters.push(some_compression);
} }
let already_has_parameters = url.contains("?") && url.contains("="); let mut has_parameters = url.contains('?') && url.contains('=');
if !already_has_parameters { if !has_parameters {
// Insure it ends in a /, so we don't get a 400 error // Insure it ends in a /, so we don't get a 400 error
if !url.ends_with('/') { if !url.ends_with('/') {
url.push('/'); url.push('/');
@ -50,12 +50,13 @@ impl GatewayOptions {
// Lets hope that if it already has parameters the person knew to add '/' // Lets hope that if it already has parameters the person knew to add '/'
} }
for index in 0..parameters.len() { for parameter in parameters {
if index == 0 && !already_has_parameters { if !has_parameters {
url = format!("{}?{}", url, parameters[index]); url = format!("{}?{}", url, parameter);
has_parameters = true;
} }
else { else {
url = format!("{}&{}", url, parameters[index]); url = format!("{}&{}", url, parameter);
} }
} }
@ -81,7 +82,7 @@ impl GatewayTransportCompression {
/// If set to [GatewayTransportCompression::None] returns [None]. /// If set to [GatewayTransportCompression::None] returns [None].
/// ///
/// If set to anything else, returns a string like "compress=zlib-stream" /// If set to anything else, returns a string like "compress=zlib-stream"
pub(crate) fn to_url_parameter(&self) -> Option<String> { pub(crate) fn to_url_parameter(self) -> Option<String> {
match self { match self {
Self::None => None, Self::None => None,
Self::ZLibStream => Some(String::from("compress=zlib-stream")) Self::ZLibStream => Some(String::from("compress=zlib-stream"))
@ -108,7 +109,7 @@ impl GatewayEncoding {
/// Returns the option as a url parameter. /// Returns the option as a url parameter.
/// ///
/// Returns a string like "encoding=json" /// Returns a string like "encoding=json"
pub(crate) fn to_url_parameter(&self) -> String { pub(crate) fn to_url_parameter(self) -> String {
match self { match self {
Self::Json => String::from("encoding=json"), Self::Json => String::from("encoding=json"),
Self::ETF => String::from("encoding=etf") Self::ETF => String::from("encoding=etf")

View File

@ -4,7 +4,6 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_string_from_number;
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use std::fmt::Debug; use std::fmt::Debug;

View File

@ -4,11 +4,9 @@
use crate::types::utils::Snowflake; use crate::types::utils::Snowflake;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_option_number_from_string; use serde_aux::prelude::deserialize_option_number_from_string;
use std::fmt::Debug; use std::fmt::Debug;
use std::num::ParseIntError;
use std::str::FromStr;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Updateable; use crate::gateway::Updateable;

View File

@ -3,10 +3,9 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use bitflags::bitflags; use bitflags::bitflags;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Serialize};
use serde::de::Visitor;
use crate::types::{ChannelType, DefaultReaction, Error, entities::PermissionOverwrite, Snowflake}; use crate::types::{ChannelType, DefaultReaction, entities::PermissionOverwrite, Snowflake};
#[derive(Debug, Deserialize, Serialize, Default, PartialEq, PartialOrd)] #[derive(Debug, Deserialize, Serialize, Default, PartialEq, PartialOrd)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]

View File

@ -24,20 +24,3 @@ impl From<WsMessage> for VoiceGatewayMessage {
} }
} }
impl From<RawGatewayMessage> for WsMessage {
fn from(message: RawGatewayMessage) -> Self {
match message {
RawGatewayMessage::Text(text) => tungstenite::Message::Text(text),
RawGatewayMessage::Bytes(bytes) => tungstenite::Message::Binary(bytes),
}
}
}
impl From<WsMessage> for RawGatewayMessage {
fn from(value: WsMessage) -> Self {
match value {
WsMessage::Binary(bytes) => RawGatewayMessage::Bytes(bytes),
WsMessage::Text(text) => RawGatewayMessage::Text(text),
}
}
}