Change UpdateMessage<T> to write into RwLock

This commit is contained in:
bitfl0wer 2023-08-13 16:46:57 +02:00
parent 8ca4ba6e50
commit 9ce575944c
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
2 changed files with 8 additions and 3 deletions

View File

@ -1,3 +1,5 @@
use std::sync::{Arc, RwLock};
use crate::types::events::WebSocketEvent;
use crate::types::{entities::Channel, Snowflake};
use chrono::{DateTime, Utc};
@ -34,8 +36,9 @@ pub struct ChannelUpdate {
impl WebSocketEvent for ChannelUpdate {}
impl UpdateMessage<Channel> for ChannelUpdate {
fn update(&self, object_to_update: &mut Channel) {
*object_to_update = self.channel.clone();
fn update(&self, object_to_update: Arc<RwLock<Channel>>) {
let mut write = object_to_update.write().unwrap();
*write = self.channel.clone();
}
fn id(&self) -> Snowflake {
self.channel.id

View File

@ -1,3 +1,5 @@
use std::sync::{Arc, RwLock};
use serde::{Deserialize, Serialize};
pub use application::*;
@ -113,6 +115,6 @@ pub(crate) trait UpdateMessage<T>: Clone
where
T: Updateable,
{
fn update(&self, object_to_update: &mut T);
fn update(&self, object_to_update: Arc<RwLock<T>>);
fn id(&self) -> Snowflake;
}