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 crate::gateway::GatewayMessage;
use crate::gateway::{GatewayMessage, RawGatewayMessage};
#[derive(Debug, Clone)]
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()
}
GatewayTransportCompression::ZLibStream => {
let message_bytes = raw_message.to_bytes();
let message_bytes = raw_message.into_bytes();
let can_decompress = message_bytes.len() > 4
&& message_bytes[message_bytes.len() - 4..] == ZLIB_SUFFIX;

View File

@ -19,7 +19,7 @@ pub(crate) enum RawGatewayMessage {
impl RawGatewayMessage {
/// 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 {
RawGatewayMessage::Text(text) => Ok(text),
RawGatewayMessage::Bytes(bytes) => String::from_utf8(bytes),
@ -27,7 +27,7 @@ impl RawGatewayMessage {
}
/// 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 {
RawGatewayMessage::Text(text) => text.as_bytes().to_vec(),
RawGatewayMessage::Bytes(bytes) => bytes,
@ -79,7 +79,7 @@ impl GatewayMessage {
pub(crate) fn from_raw_json_message(
message: RawGatewayMessage,
) -> Result<GatewayMessage, FromUtf8Error> {
let text = message.to_text()?;
let text = message.into_text()?;
Ok(GatewayMessage(text))
}
@ -105,6 +105,6 @@ impl GatewayMessage {
message: RawGatewayMessage,
inflate: &mut flate2::Decompress,
) -> 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);
}
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
if !url.ends_with('/') {
url.push('/');
@ -50,12 +50,13 @@ impl GatewayOptions {
// Lets hope that if it already has parameters the person knew to add '/'
}
for index in 0..parameters.len() {
if index == 0 && !already_has_parameters {
url = format!("{}?{}", url, parameters[index]);
for parameter in parameters {
if !has_parameters {
url = format!("{}?{}", url, parameter);
has_parameters = true;
}
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 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 {
Self::None => None,
Self::ZLibStream => Some(String::from("compress=zlib-stream"))
@ -108,7 +109,7 @@ impl GatewayEncoding {
/// Returns the option as a url parameter.
///
/// Returns a string like "encoding=json"
pub(crate) fn to_url_parameter(&self) -> String {
pub(crate) fn to_url_parameter(self) -> String {
match self {
Self::Json => String::from("encoding=json"),
Self::ETF => String::from("encoding=etf")

View File

@ -4,7 +4,6 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_aux::prelude::deserialize_string_from_number;
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::fmt::Debug;
@ -274,4 +273,4 @@ pub enum ChannelType {
pub struct FollowedChannel {
pub channel_id: Snowflake,
pub webhook_id: Snowflake
}
}

View File

@ -429,4 +429,4 @@ pub struct PartialEmoji {
pub enum ReactionType {
Normal = 0,
Burst = 1, // The dreaded super reactions
}
}

View File

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

View File

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

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),
}
}
}