Move Shared<T> to types/mod.rs, bump some dependencies (#492)

* deps: bump rustls to 0.21.11

This is done to fix CVE-2024-32650, which practically shouldn't affect
us but it's still better not to use vulnerable dependencies.

* deps: bump h2 to 0.3.26

This is done to fix another vulnerability, which should also not affect
us (non-critical, in h2 servers)

* fix: move Shared<T> to types/mod.rs
This commit is contained in:
kozabrada123 2024-04-28 14:15:57 +02:00 committed by GitHub
parent 319748c0a7
commit b2fd3e18cc
27 changed files with 51 additions and 44 deletions

8
Cargo.lock generated
View File

@ -716,9 +716,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.24" version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -1753,9 +1753,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.21.10" version = "0.21.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4"
dependencies = [ dependencies = [
"log", "log",
"ring 0.17.7", "ring 0.17.7",

View File

@ -8,7 +8,7 @@ use log::*;
use std::fmt::Debug; use std::fmt::Debug;
use super::{events::Events, *}; use super::{events::Events, *};
use crate::types::{self, Composite}; use crate::types::{self, Composite, Shared};
/// Represents a handle to a Gateway connection. A Gateway connection will create observable /// Represents a handle to a Gateway connection. A Gateway connection will create observable
/// [`GatewayEvents`](GatewayEvent), which you can subscribe to. Gateway events include all currently /// [`GatewayEvents`](GatewayEvent), which you can subscribe to. Gateway events include all currently

View File

@ -133,10 +133,3 @@ impl<T: WebSocketEvent> GatewayEvent<T> {
} }
} }
/// A type alias for [`Arc<RwLock<T>>`], used to make the public facing API concerned with
/// Composite structs more ergonomic.
/// ## Note
///
/// While `T` does not have to implement `Composite` to be used with `Shared`,
/// the primary use of `Shared` is with types that implement `Composite`.
pub type Shared<T> = Arc<RwLock<T>>;

View File

@ -13,11 +13,11 @@ use reqwest::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::errors::ChorusResult; use crate::errors::ChorusResult;
use crate::gateway::{Gateway, GatewayHandle, Shared}; use crate::gateway::{Gateway, GatewayHandle};
use crate::ratelimiter::ChorusRequest; use crate::ratelimiter::ChorusRequest;
use crate::types::types::subconfigs::limits::rates::RateLimits; use crate::types::types::subconfigs::limits::rates::RateLimits;
use crate::types::{ use crate::types::{
GeneralConfiguration, Limit, LimitType, LimitsConfiguration, User, UserSettings, GeneralConfiguration, Limit, LimitType, LimitsConfiguration, Shared, User, UserSettings,
}; };
use crate::UrlBundle; use crate::UrlBundle;

View File

@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::gateway::Shared; use crate::types::Shared;
use crate::types::utils::Snowflake; use crate::types::utils::Snowflake;
use crate::types::{Team, User}; use crate::types::{Team, User};

View File

@ -4,7 +4,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::Shared;
use crate::types::utils::Snowflake; use crate::types::utils::Snowflake;
#[derive(Serialize, Deserialize, Debug, Default, Clone)] #[derive(Serialize, Deserialize, Debug, Default, Clone)]

View File

@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::gateway::Shared; use crate::types::Shared;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Updateable; use crate::gateway::Updateable;

View File

@ -8,7 +8,7 @@ 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;
use crate::gateway::Shared; use crate::types::Shared;
use crate::types::{ use crate::types::{
entities::{GuildMember, User}, entities::{GuildMember, User},
utils::Snowflake, utils::Snowflake,

View File

@ -6,7 +6,7 @@ use std::fmt::Debug;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::Shared;
use crate::types::entities::User; use crate::types::entities::User;
use crate::types::Snowflake; use crate::types::Snowflake;

View File

@ -9,7 +9,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::gateway::Shared; use crate::types::Shared;
use crate::types::types::guild_configuration::GuildFeaturesList; use crate::types::types::guild_configuration::GuildFeaturesList;
use crate::types::{ use crate::types::{
entities::{Channel, Emoji, RoleObject, Sticker, User, VoiceState, Webhook}, entities::{Channel, Emoji, RoleObject, Sticker, User, VoiceState, Webhook},

View File

@ -4,7 +4,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::Shared;
use crate::types::{entities::PublicUser, Snowflake}; use crate::types::{entities::PublicUser, Snowflake};
#[derive(Debug, Deserialize, Default, Serialize, Clone)] #[derive(Debug, Deserialize, Default, Serialize, Clone)]

View File

@ -5,8 +5,8 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared;
use crate::types::{ use crate::types::{
Shared,
entities::{Application, User}, entities::{Application, User},
utils::Snowflake, utils::Snowflake,
}; };

View File

@ -5,8 +5,7 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::{Snowflake, WelcomeScreenObject, Shared};
use crate::types::{Snowflake, WelcomeScreenObject};
use super::guild::GuildScheduledEvent; use super::guild::GuildScheduledEvent;
use super::{Application, Channel, GuildMember, NSFWLevel, User}; use super::{Application, Channel, GuildMember, NSFWLevel, User};

View File

@ -4,8 +4,8 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared;
use crate::types::{ use crate::types::{
Shared,
entities::{ entities::{
Application, Attachment, Channel, Emoji, GuildMember, PublicUser, RoleSubscriptionData, Application, Attachment, Channel, Emoji, GuildMember, PublicUser, RoleSubscriptionData,
Sticker, StickerItem, User, Sticker, StickerItem, User,

View File

@ -27,7 +27,9 @@ pub use user_settings::*;
pub use voice_state::*; pub use voice_state::*;
pub use webhook::*; pub use webhook::*;
use crate::gateway::Shared; use crate::types::Shared;
use std::sync::{Arc, RwLock};
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Updateable; use crate::gateway::Updateable;
@ -39,8 +41,6 @@ use async_trait::async_trait;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use std::fmt::Debug; use std::fmt::Debug;
#[cfg(feature = "client")]
use std::sync::{Arc, RwLock};
mod application; mod application;
mod attachment; mod attachment;

View File

@ -6,8 +6,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::gateway::Shared; use crate::types::{Shared, Snowflake};
use crate::types::Snowflake;
use super::PublicUser; use super::PublicUser;

View File

@ -4,8 +4,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::{entities::User, utils::Snowflake, Shared};
use crate::types::{entities::User, utils::Snowflake};
#[derive(Debug, Serialize, Deserialize, Clone, Default)] #[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]

View File

@ -4,9 +4,9 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared;
use crate::types::entities::User; use crate::types::entities::User;
use crate::types::Snowflake; use crate::types::Snowflake;
use crate::types::Shared;
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]

View File

@ -5,8 +5,8 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared;
use crate::types::{ use crate::types::{
Shared,
entities::{Guild, User}, entities::{Guild, User},
utils::Snowflake, utils::Snowflake,
}; };

View File

@ -7,7 +7,7 @@ use std::sync::{Arc, RwLock};
use chrono::{serde::ts_milliseconds_option, Utc}; use chrono::{serde::ts_milliseconds_option, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::Shared;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))] #[cfg_attr(feature = "sqlx", derive(sqlx::Type))]

View File

@ -5,7 +5,8 @@
#[cfg(feature = "client")] #[cfg(feature = "client")]
use chorus_macros::Composite; use chorus_macros::Composite;
use crate::gateway::Shared; use crate::types::Shared;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::types::Composite; use crate::types::Composite;
@ -51,6 +52,7 @@ pub struct VoiceState {
pub id: Option<Snowflake>, // Only exists on Spacebar pub id: Option<Snowflake>, // Only exists on Spacebar
} }
#[cfg(feature = "client")]
impl Updateable for VoiceState { impl Updateable for VoiceState {
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
fn id(&self) -> Snowflake { fn id(&self) -> Snowflake {

View File

@ -6,7 +6,8 @@ use std::fmt::Debug;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::gateway::Shared; use crate::types::Shared;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Updateable; use crate::gateway::Updateable;

View File

@ -3,7 +3,6 @@
// 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 crate::types::events::WebSocketEvent; use crate::types::events::WebSocketEvent;
use crate::types::IntoShared;
use crate::types::{entities::Channel, JsonField, Snowflake, SourceUrlField}; use crate::types::{entities::Channel, JsonField, Snowflake, SourceUrlField};
use chorus_macros::{JsonField, SourceUrlField}; use chorus_macros::{JsonField, SourceUrlField};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
@ -13,7 +12,10 @@ use serde::{Deserialize, Serialize};
use super::UpdateMessage; use super::UpdateMessage;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Shared; use crate::types::Shared;
#[cfg(feature = "client")]
use crate::types::IntoShared;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::types::Guild; use crate::types::Guild;

View File

@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::types::entities::{Guild, PublicUser, UnavailableGuild}; use crate::types::entities::{Guild, PublicUser, UnavailableGuild};
use crate::types::events::WebSocketEvent; use crate::types::events::WebSocketEvent;
use crate::types::{ use crate::types::{
AuditLogEntry, Emoji, GuildMember, GuildScheduledEvent, IntoShared, JsonField, RoleObject, AuditLogEntry, Emoji, GuildMember, GuildScheduledEvent, JsonField, RoleObject,
Snowflake, SourceUrlField, Sticker, Snowflake, SourceUrlField, Sticker,
}; };
@ -18,7 +18,9 @@ use super::PresenceUpdate;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use super::UpdateMessage; use super::UpdateMessage;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Shared; use crate::types::Shared;
#[cfg(feature = "client")]
use crate::types::IntoShared;
#[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField, WebSocketEvent)] #[derive(Debug, Deserialize, Serialize, Default, Clone, SourceUrlField, JsonField, WebSocketEvent)]
/// See <https://discord.com/developers/docs/topics/gateway-events#guild-create>; /// See <https://discord.com/developers/docs/topics/gateway-events#guild-create>;

View File

@ -48,7 +48,7 @@ use serde_json::{from_str, from_value, to_value, Value};
use std::collections::HashMap; use std::collections::HashMap;
#[cfg(feature = "client")] #[cfg(feature = "client")]
use crate::gateway::Shared; use crate::types::Shared;
use std::fmt::Debug; use std::fmt::Debug;
#[cfg(feature = "client")] #[cfg(feature = "client")]

View File

@ -4,6 +4,8 @@
//! All the types, entities, events and interfaces of the Spacebar API. //! All the types, entities, events and interfaces of the Spacebar API.
use std::sync::{Arc, RwLock};
pub use config::*; pub use config::*;
pub use entities::*; pub use entities::*;
pub use errors::*; pub use errors::*;
@ -19,3 +21,11 @@ mod events;
mod interfaces; mod interfaces;
mod schema; mod schema;
mod utils; mod utils;
/// A type alias for [`Arc<RwLock<T>>`], used to make the public facing API concerned with
/// Composite structs more ergonomic.
/// ## Note
///
/// While `T` does not have to implement `Composite` to be used with `Shared`,
/// the primary use of `Shared` is with types that implement `Composite`.
pub type Shared<T> = Arc<RwLock<T>>;

View File

@ -2,13 +2,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use chorus::gateway::{Gateway, Shared}; use chorus::gateway::Gateway;
use chorus::types::IntoShared; use chorus::types::IntoShared;
use chorus::{ use chorus::{
instance::{ChorusUser, Instance}, instance::{ChorusUser, Instance},
types::{ types::{
Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema, Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema,
RoleCreateModifySchema, RoleObject, RoleCreateModifySchema, RoleObject, Shared
}, },
UrlBundle, UrlBundle,
}; };