Change Arc<Mutex<T>> components to Arc<RwLock<T>>

This commit is contained in:
bitfl0wer 2023-08-04 17:57:03 +02:00
parent 1eb581c049
commit 38a97fc37a
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
20 changed files with 69 additions and 69 deletions

View File

@ -1,6 +1,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use reqwest::Client;
use serde_json::to_string;

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use std::{cell::RefCell, rc::Rc};
use reqwest::Client;

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use std::{cell::RefCell, rc::Rc};
use reqwest::Client;

View File

@ -2,7 +2,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use reqwest::Client;
use serde::{Deserialize, Serialize};
@ -91,8 +91,8 @@ pub struct UserMeta {
pub belongs_to: Rc<RefCell<Instance>>,
pub token: String,
pub limits: Option<HashMap<LimitType, Limit>>,
pub settings: Arc<Mutex<UserSettings>>,
pub object: Arc<Mutex<User>>,
pub settings: Arc<RwLock<UserSettings>>,
pub object: Arc<RwLock<User>>,
pub gateway: GatewayHandle,
}
@ -114,8 +114,8 @@ impl UserMeta {
belongs_to: Rc<RefCell<Instance>>,
token: String,
limits: Option<HashMap<LimitType, Limit>>,
settings: Arc<Mutex<UserSettings>>,
object: Arc<Mutex<User>>,
settings: Arc<RwLock<UserSettings>>,
object: Arc<RwLock<User>>,
gateway: GatewayHandle,
) -> UserMeta {
UserMeta {
@ -134,8 +134,8 @@ impl UserMeta {
/// need to make a RateLimited request. To use the [`GatewayHandle`], you will have to identify
/// first.
pub(crate) async fn shell(instance: Rc<RefCell<Instance>>, token: String) -> UserMeta {
let settings = Arc::new(Mutex::new(UserSettings::default()));
let object = Arc::new(Mutex::new(User::default()));
let settings = Arc::new(RwLock::new(UserSettings::default()));
let object = Arc::new(RwLock::new(User::default()));
let wss_url = instance.borrow().urls.wss.clone();
// Dummy gateway object
let gateway = Gateway::new(wss_url).await.unwrap();

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use bitflags::bitflags;
use serde::{Deserialize, Serialize};
@ -27,7 +27,7 @@ pub struct Application {
pub bot_require_code_grant: bool,
pub verify_key: String,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub owner: Arc<Mutex<User>>,
pub owner: Arc<RwLock<User>>,
pub flags: u64,
#[cfg(feature = "sqlx")]
pub redirect_uris: Option<sqlx::types::Json<Vec<String>>>,
@ -49,7 +49,7 @@ pub struct Application {
#[cfg(feature = "sqlx")]
pub install_params: Option<sqlx::types::Json<InstallParams>>,
#[cfg(not(feature = "sqlx"))]
pub install_params: Option<Arc<Mutex<InstallParams>>>,
pub install_params: Option<Arc<RwLock<InstallParams>>>,
pub terms_of_service_url: Option<String>,
pub privacy_policy_url: Option<String>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
@ -142,7 +142,7 @@ pub struct ApplicationCommand {
pub application_id: Snowflake,
pub name: String,
pub description: String,
pub options: Vec<Arc<Mutex<ApplicationCommandOption>>>,
pub options: Vec<Arc<RwLock<ApplicationCommandOption>>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -154,7 +154,7 @@ pub struct ApplicationCommandOption {
pub description: String,
pub required: bool,
pub choices: Vec<ApplicationCommandOptionChoice>,
pub options: Arc<Mutex<Vec<ApplicationCommandOption>>>,
pub options: Arc<RwLock<Vec<ApplicationCommandOption>>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -190,14 +190,14 @@ pub enum ApplicationCommandOptionType {
pub struct ApplicationCommandInteractionData {
pub id: Snowflake,
pub name: String,
pub options: Vec<Arc<Mutex<ApplicationCommandInteractionDataOption>>>,
pub options: Vec<Arc<RwLock<ApplicationCommandInteractionDataOption>>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApplicationCommandInteractionDataOption {
pub name: String,
pub value: Value,
pub options: Vec<Arc<Mutex<ApplicationCommandInteractionDataOption>>>,
pub options: Vec<Arc<RwLock<ApplicationCommandInteractionDataOption>>>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
@ -206,7 +206,7 @@ pub struct GuildApplicationCommandPermissions {
pub id: Snowflake,
pub application_id: Snowflake,
pub guild_id: Snowflake,
pub permissions: Vec<Arc<Mutex<ApplicationCommandPermission>>>,
pub permissions: Vec<Arc<RwLock<ApplicationCommandPermission>>>,
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
@ -8,7 +8,7 @@ use crate::types::utils::Snowflake;
/// See <https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object>
pub struct AuditLogEntry {
pub target_id: Option<String>,
pub changes: Option<Vec<Arc<Mutex<AuditLogChange>>>>,
pub changes: Option<Vec<Arc<RwLock<AuditLogChange>>>>,
pub user_id: Option<Snowflake>,
pub id: Snowflake,
// to:do implement an enum for these types

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
@ -14,8 +14,8 @@ pub struct AutoModerationRule {
pub creator_id: Snowflake,
pub event_type: AutoModerationRuleEventType,
pub trigger_type: AutoModerationRuleTriggerType,
pub trigger_metadata: Arc<Mutex<AutoModerationRuleTriggerMetadata>>,
pub actions: Vec<Arc<Mutex<AutoModerationAction>>>,
pub trigger_metadata: Arc<RwLock<AutoModerationRuleTriggerMetadata>>,
pub actions: Vec<Arc<RwLock<AutoModerationAction>>>,
pub enabled: bool,
pub exempt_roles: Vec<Snowflake>,
pub exempt_channels: Vec<Snowflake>,
@ -92,7 +92,7 @@ pub enum AutoModerationRuleKeywordPresetType {
pub struct AutoModerationAction {
#[serde(rename = "type")]
pub action_type: AutoModerationActionType,
pub metadata: Option<Arc<Mutex<AutoModerationActionMetadata>>>,
pub metadata: Option<Arc<RwLock<AutoModerationActionMetadata>>>,
}
#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)]

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chorus_macros::Updateable;
use chrono::Utc;
@ -48,7 +48,7 @@ pub struct Channel {
pub last_pin_timestamp: Option<String>,
pub managed: Option<bool>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub member: Option<Arc<Mutex<ThreadMember>>>,
pub member: Option<Arc<RwLock<ThreadMember>>>,
pub member_count: Option<i32>,
pub message_count: Option<i32>,
pub name: Option<String>,
@ -58,12 +58,12 @@ pub struct Channel {
#[cfg(feature = "sqlx")]
pub permission_overwrites: Option<sqlx::types::Json<Vec<PermissionOverwrite>>>,
#[cfg(not(feature = "sqlx"))]
pub permission_overwrites: Option<Vec<Arc<Mutex<PermissionOverwrite>>>>,
pub permission_overwrites: Option<Vec<Arc<RwLock<PermissionOverwrite>>>>,
pub permissions: Option<String>,
pub position: Option<i32>,
pub rate_limit_per_user: Option<i32>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub recipients: Option<Vec<Arc<Mutex<User>>>>,
pub recipients: Option<Vec<Arc<RwLock<User>>>>,
pub rtc_region: Option<String>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub thread_metadata: Option<ThreadMetadata>,
@ -156,7 +156,7 @@ pub struct ThreadMember {
pub user_id: Option<Snowflake>,
pub join_timestamp: Option<String>,
pub flags: Option<u64>,
pub member: Option<Arc<Mutex<GuildMember>>>,
pub member: Option<Arc<RwLock<GuildMember>>>,
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
@ -17,7 +17,7 @@ pub struct Emoji {
#[cfg(not(feature = "sqlx"))]
pub roles: Option<Vec<Snowflake>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Arc<Mutex<User>>>,
pub user: Option<Arc<RwLock<User>>>,
pub require_colons: Option<bool>,
pub managed: Option<bool>,
pub animated: Option<bool>,

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -27,13 +27,13 @@ pub struct Guild {
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub bans: Option<Vec<GuildBan>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub channels: Option<Vec<Arc<Mutex<Channel>>>>,
pub channels: Option<Vec<Arc<RwLock<Channel>>>>,
pub default_message_notifications: Option<i32>,
pub description: Option<String>,
pub discovery_splash: Option<String>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
#[serde(default)]
pub emojis: Vec<Arc<Mutex<Emoji>>>,
pub emojis: Vec<Arc<RwLock<Emoji>>>,
pub explicit_content_filter: Option<i32>,
//#[cfg_attr(feature = "sqlx", sqlx(try_from = "String"))]
pub features: Option<GuildFeaturesList>,
@ -42,7 +42,7 @@ pub struct Guild {
pub icon_hash: Option<String>,
pub id: Snowflake,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub invites: Option<Vec<Arc<Mutex<GuildInvite>>>>,
pub invites: Option<Vec<Arc<RwLock<GuildInvite>>>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub joined_at: Option<String>,
pub large: Option<bool>,
@ -68,7 +68,7 @@ pub struct Guild {
pub public_updates_channel_id: Option<Snowflake>,
pub region: Option<String>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub roles: Option<Vec<Arc<Mutex<RoleObject>>>>,
pub roles: Option<Vec<Arc<RwLock<RoleObject>>>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub rules_channel: Option<String>,
pub rules_channel_id: Option<Snowflake>,
@ -81,13 +81,13 @@ pub struct Guild {
pub vanity_url_code: Option<String>,
pub verification_level: Option<i32>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub voice_states: Option<Vec<Arc<Mutex<VoiceState>>>>,
pub voice_states: Option<Vec<Arc<RwLock<VoiceState>>>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub webhooks: Option<Vec<Arc<Mutex<Webhook>>>>,
pub webhooks: Option<Vec<Arc<RwLock<Webhook>>>>,
#[cfg(feature = "sqlx")]
pub welcome_screen: Option<sqlx::types::Json<WelcomeScreenObject>>,
#[cfg(not(feature = "sqlx"))]
pub welcome_screen: Option<Arc<Mutex<WelcomeScreenObject>>>,
pub welcome_screen: Option<Arc<RwLock<WelcomeScreenObject>>>,
pub widget_channel_id: Option<Snowflake>,
pub widget_enabled: Option<bool>,
}
@ -113,11 +113,11 @@ pub struct GuildInvite {
pub created_at: DateTime<Utc>,
pub expires_at: Option<DateTime<Utc>>,
pub guild_id: Snowflake,
pub guild: Option<Arc<Mutex<Guild>>>,
pub guild: Option<Arc<RwLock<Guild>>>,
pub channel_id: Snowflake,
pub channel: Option<Arc<Mutex<Channel>>>,
pub channel: Option<Arc<RwLock<Channel>>>,
pub inviter_id: Option<Snowflake>,
pub inviter: Option<Arc<Mutex<User>>>,
pub inviter: Option<Arc<RwLock<User>>>,
pub target_user_id: Option<Snowflake>,
pub target_user: Option<String>,
pub target_user_type: Option<i32>,
@ -151,7 +151,7 @@ pub struct GuildScheduledEvent {
pub entity_type: GuildScheduledEventEntityType,
pub entity_id: Option<Snowflake>,
pub entity_metadata: Option<GuildScheduledEventEntityMetadata>,
pub creator: Option<Arc<Mutex<User>>>,
pub creator: Option<Arc<RwLock<User>>>,
pub user_count: Option<u64>,
pub image: Option<String>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
@ -10,7 +10,7 @@ use crate::types::{entities::PublicUser, Snowflake};
/// # Reference
/// See <https://discord-userdoccers.vercel.app/resources/guild#guild-member-object>
pub struct GuildMember {
pub user: Option<Arc<Mutex<PublicUser>>>,
pub user: Option<Arc<RwLock<PublicUser>>>,
pub nick: Option<String>,
pub avatar: Option<String>,
pub roles: Vec<Snowflake>,

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -23,14 +23,14 @@ pub struct Integration {
pub expire_behaviour: Option<u8>,
pub expire_grace_period: Option<u16>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Arc<Mutex<User>>>,
pub user: Option<Arc<RwLock<User>>>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub account: IntegrationAccount,
pub synced_at: Option<DateTime<Utc>>,
pub subscriber_count: Option<f64>,
pub revoked: Option<bool>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub application: Option<Arc<Mutex<Application>>>,
pub application: Option<Arc<RwLock<Application>>>,
pub scopes: Option<Vec<String>>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -70,7 +70,7 @@ pub enum NSFWLevel {
/// See <https://discord-userdoccers.vercel.app/resources/invite#invite-stage-instance-object>
#[derive(Debug, Serialize, Deserialize)]
pub struct InviteStageInstance {
pub members: Vec<Arc<Mutex<GuildMember>>>,
pub members: Vec<Arc<RwLock<GuildMember>>>,
pub participant_count: i32,
pub speaker_count: i32,
pub topic: String,

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -15,7 +15,7 @@ pub struct Relationship {
#[serde(rename = "type")]
pub relationship_type: RelationshipType,
pub nickname: Option<String>,
pub user: Arc<Mutex<PublicUser>>,
pub user: Arc<RwLock<PublicUser>>,
pub since: Option<DateTime<Utc>>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
@ -24,7 +24,7 @@ pub struct Sticker {
pub available: Option<bool>,
pub guild_id: Option<Snowflake>,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Arc<Mutex<User>>>,
pub user: Option<Arc<RwLock<User>>>,
pub sort_value: Option<u8>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
@ -21,5 +21,5 @@ pub struct TeamMember {
pub membership_state: u8,
pub permissions: Vec<String>,
pub team_id: Snowflake,
pub user: Arc<Mutex<User>>,
pub user: Arc<RwLock<User>>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -18,13 +18,13 @@ pub struct GuildTemplate {
pub usage_count: Option<u64>,
pub creator_id: Snowflake,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub creator: Arc<Mutex<User>>,
pub creator: Arc<RwLock<User>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub source_guild_id: Snowflake,
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub source_guild: Vec<Arc<Mutex<Guild>>>,
pub source_guild: Vec<Arc<RwLock<Guild>>>,
// Unsure how a {recursive: Guild} looks like, might be a Vec?
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub serialized_source_guild: Vec<Arc<Mutex<Guild>>>,
pub serialized_source_guild: Vec<Arc<RwLock<Guild>>>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{serde::ts_milliseconds_option, Utc};
use serde::{Deserialize, Serialize};
@ -75,7 +75,7 @@ pub struct UserSettings {
#[cfg(not(feature = "sqlx"))]
pub restricted_guilds: Vec<String>,
pub show_current_game: bool,
pub status: Arc<Mutex<UserStatus>>,
pub status: Arc<RwLock<UserStatus>>,
pub stream_notifications_enabled: bool,
pub theme: UserTheme,
pub timezone_offset: i16,
@ -111,7 +111,7 @@ impl Default for UserSettings {
render_reactions: true,
restricted_guilds: Default::default(),
show_current_game: true,
status: Arc::new(Mutex::new(UserStatus::Online)),
status: Arc::new(RwLock::new(UserStatus::Online)),
stream_notifications_enabled: false,
theme: UserTheme::Dark,
timezone_offset: 0,
@ -151,5 +151,5 @@ pub struct GuildFolder {
#[derive(Debug, Serialize, Deserialize)]
pub struct LoginResult {
pub token: String,
pub settings: Arc<Mutex<UserSettings>>,
pub settings: Arc<RwLock<UserSettings>>,
}

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -16,7 +16,7 @@ pub struct VoiceState {
pub guild: Option<Guild>,
pub channel_id: Option<Snowflake>,
pub user_id: Snowflake,
pub member: Option<Arc<Mutex<GuildMember>>>,
pub member: Option<Arc<RwLock<GuildMember>>>,
pub session_id: Snowflake,
pub token: Option<String>,
pub deaf: bool,

View File

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
@ -22,10 +22,10 @@ pub struct Webhook {
pub application_id: Snowflake,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub user: Option<Arc<Mutex<User>>>,
pub user: Option<Arc<RwLock<User>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "sqlx", sqlx(skip))]
pub source_guild: Option<Arc<Mutex<Guild>>>,
pub source_guild: Option<Arc<RwLock<Guild>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
}