]> git.lizzy.rs Git - mt_rudp.git/commitdiff
Get rid of Cell usage
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Thu, 9 Feb 2023 15:48:26 +0000 (16:48 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Thu, 9 Feb 2023 15:48:26 +0000 (16:48 +0100)
src/lib.rs
src/recv.rs

index f0a91fe955a0f754a394ec075fbd4565f1f4d903..334692a4ec3c43da52e1c6a771cffb486b932c0e 100644 (file)
@@ -11,13 +11,7 @@ pub use prelude::*;
 
 use async_trait::async_trait;
 use num_enum::TryFromPrimitive;
-use std::{
-    cell::{Cell, OnceCell},
-    collections::HashMap,
-    io, ops,
-    sync::Arc,
-    time::Instant,
-};
+use std::{cell::OnceCell, collections::HashMap, io, ops, sync::Arc, time::Instant};
 use tokio::{
     sync::{mpsc, watch, Mutex, RwLock},
     task::JoinSet,
@@ -150,7 +144,7 @@ struct Split {
 }
 
 struct RecvChan {
-    packets: Vec<Cell<Option<Vec<u8>>>>, // char ** ðŸ˜›
+    packets: Vec<Option<Vec<u8>>>, // char ** ðŸ˜›
     splits: HashMap<u16, Split>,
     seqnum: u16,
     num: u8,
index e685c9c518e58058b63ad20313e14b82fadabdc2..a88426f847c4a4f650d1ad428461bb458f063dec 100644 (file)
@@ -2,7 +2,7 @@ use crate::{prelude::*, ticker, RecvChan, RecvWorker, RudpShare, Split};
 use async_recursion::async_recursion;
 use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
 use std::{
-    cell::{Cell, OnceCell},
+    cell::OnceCell,
     collections::HashMap,
     io,
     pin::Pin,
@@ -34,7 +34,7 @@ impl<R: UdpReceiver, S: UdpSender> RecvWorker<R, S> {
                     .map(|num| {
                         Mutex::new(RecvChan {
                             num,
-                            packets: (0..REL_BUFFER).map(|_| Cell::new(None)).collect(),
+                            packets: (0..REL_BUFFER).map(|_| None).collect(),
                             seqnum: INIT_SEQNUM,
                             splits: HashMap::new(),
                         })
@@ -239,7 +239,7 @@ impl<R: UdpReceiver, S: UdpSender> RecvWorker<R, S> {
                 println!("Rel");
 
                 let seqnum = cursor.read_u16::<BigEndian>()?;
-                chan.packets[to_seqnum(seqnum)].set(Some(cursor.remaining_slice().into()));
+                chan.packets[to_seqnum(seqnum)].replace(cursor.remaining_slice().into());
 
                 let mut ack_data = Vec::with_capacity(3);
                 ack_data.write_u8(CtlType::Ack as u8)?;