]> git.lizzy.rs Git - mt_rudp.git/blobdiff - src/send.rs
Use Cow for Pkt
[mt_rudp.git] / src / send.rs
index e0c2fa3a4407f9992ea15ab5f48864181ec0ed82..a3a7f036e5e2ea4639ed6267cbacf5e4b7441b25 100644 (file)
@@ -6,13 +6,13 @@ use tokio::sync::watch;
 pub type AckResult = io::Result<Option<watch::Receiver<bool>>>;
 
 impl<S: UdpSender> RudpSender<S> {
-    pub async fn send(&self, pkt: Pkt<&[u8]>) -> AckResult {
+    pub async fn send(&self, pkt: Pkt<'_>) -> AckResult {
         self.share.send(PktType::Orig, pkt).await // TODO: splits
     }
 }
 
 impl<S: UdpSender> RudpShare<S> {
-    pub async fn send(&self, tp: PktType, pkt: Pkt<&[u8]>) -> AckResult {
+    pub async fn send(&self, tp: PktType, pkt: Pkt<'_>) -> AckResult {
         let mut buf = Vec::with_capacity(4 + 2 + 1 + 1 + 2 + 1 + pkt.data.len());
         buf.write_u32::<BigEndian>(PROTO_ID)?;
         buf.write_u16::<BigEndian>(*self.remote_id.read().await)?;
@@ -27,7 +27,7 @@ impl<S: UdpSender> RudpShare<S> {
         }
 
         buf.write_u8(tp as u8)?;
-        buf.write_all(pkt.data)?;
+        buf.write_all(pkt.data.as_ref())?;
 
         self.send_raw(&buf).await?;