Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit d1e869f

Browse files
author
Rain Liu
committed
make packet trait as Send + Sync
1 parent 965dc04 commit d1e869f

File tree

15 files changed

+38
-38
lines changed

15 files changed

+38
-38
lines changed

src/compound_packet/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::fmt;
2525
///
2626
/// Other RTCP packet types may follow in any order. Packet types may appear more than once.
2727
#[derive(Debug, Default, PartialEq, Clone)]
28-
pub struct CompoundPacket(pub Vec<Box<dyn Packet>>);
28+
pub struct CompoundPacket(pub Vec<Box<dyn Packet + Send + Sync>>);
2929

3030
impl fmt::Display for CompoundPacket {
3131
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -60,14 +60,14 @@ impl Packet for CompoundPacket {
6060
self
6161
}
6262

63-
fn equal(&self, other: &dyn Packet) -> bool {
63+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
6464
other
6565
.as_any()
6666
.downcast_ref::<CompoundPacket>()
6767
.map_or(false, |a| self == a)
6868
}
6969

70-
fn cloned(&self) -> Box<dyn Packet> {
70+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
7171
Box::new(self.clone())
7272
}
7373
}

src/goodbye/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ impl Packet for Goodbye {
5757
self
5858
}
5959

60-
fn equal(&self, other: &dyn Packet) -> bool {
60+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
6161
other
6262
.as_any()
6363
.downcast_ref::<Goodbye>()
6464
.map_or(false, |a| self == a)
6565
}
6666

67-
fn cloned(&self) -> Box<dyn Packet> {
67+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
6868
Box::new(self.clone())
6969
}
7070
}

src/packet.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ pub trait Packet: Marshal + Unmarshal + fmt::Display + fmt::Debug {
2121
fn destination_ssrc(&self) -> Vec<u32>;
2222
fn raw_size(&self) -> usize;
2323
fn as_any(&self) -> &dyn Any;
24-
fn equal(&self, other: &dyn Packet) -> bool;
25-
fn cloned(&self) -> Box<dyn Packet>;
24+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool;
25+
fn cloned(&self) -> Box<dyn Packet + Send + Sync>;
2626
}
2727

28-
impl PartialEq for dyn Packet {
28+
impl PartialEq for dyn Packet + Send + Sync {
2929
fn eq(&self, other: &Self) -> bool {
3030
self.equal(other)
3131
}
3232
}
3333

34-
impl Clone for Box<dyn Packet> {
35-
fn clone(&self) -> Box<dyn Packet> {
34+
impl Clone for Box<dyn Packet + Send + Sync> {
35+
fn clone(&self) -> Box<dyn Packet + Send + Sync> {
3636
self.cloned()
3737
}
3838
}
@@ -43,7 +43,7 @@ impl Clone for Box<dyn Packet> {
4343
/// If this is a reduced-size RTCP packet a feedback packet (Goodbye, SliceLossIndication, etc)
4444
/// will be returned. Otherwise, the underlying type of the returned packet will be
4545
/// CompoundPacket.
46-
pub fn unmarshal<B>(raw_data: &mut B) -> Result<Box<dyn Packet>>
46+
pub fn unmarshal<B>(raw_data: &mut B) -> Result<Box<dyn Packet + Send + Sync>>
4747
where
4848
B: Buf,
4949
{
@@ -68,7 +68,7 @@ where
6868

6969
/// unmarshaller is a factory which pulls the first RTCP packet from a bytestream,
7070
/// and returns it's parsed representation, and the amount of data that was processed.
71-
pub(crate) fn unmarshaller<B>(raw_data: &mut B) -> Result<Box<dyn Packet>>
71+
pub(crate) fn unmarshaller<B>(raw_data: &mut B) -> Result<Box<dyn Packet + Send + Sync>>
7272
where
7373
B: Buf,
7474
{
@@ -81,7 +81,7 @@ where
8181

8282
let mut in_packet = h.marshal()?.chain(raw_data.take(length));
8383

84-
let p: Box<dyn Packet> = match h.packet_type {
84+
let p: Box<dyn Packet + Send + Sync> = match h.packet_type {
8585
PacketType::SenderReport => Box::new(SenderReport::unmarshal(&mut in_packet)?),
8686
PacketType::ReceiverReport => Box::new(ReceiverReport::unmarshal(&mut in_packet)?),
8787
PacketType::SourceDescription => Box::new(SourceDescription::unmarshal(&mut in_packet)?),
@@ -185,7 +185,7 @@ mod test {
185185
media_ssrc: 0x902f9e2e,
186186
};
187187

188-
let expected: Box<dyn Packet> = Box::new(CompoundPacket(vec![
188+
let expected: Box<dyn Packet + Send + Sync> = Box::new(CompoundPacket(vec![
189189
Box::new(a),
190190
Box::new(b),
191191
Box::new(c),

src/payload_feedbacks/full_intra_request/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ impl Packet for FullIntraRequest {
6565
self
6666
}
6767

68-
fn equal(&self, other: &dyn Packet) -> bool {
68+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
6969
other
7070
.as_any()
7171
.downcast_ref::<FullIntraRequest>()
7272
.map_or(false, |a| self == a)
7373
}
7474

75-
fn cloned(&self) -> Box<dyn Packet> {
75+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
7676
Box::new(self.clone())
7777
}
7878
}

src/payload_feedbacks/picture_loss_indication/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ impl Packet for PictureLossIndication {
5454
self
5555
}
5656

57-
fn equal(&self, other: &dyn Packet) -> bool {
57+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
5858
other
5959
.as_any()
6060
.downcast_ref::<PictureLossIndication>()
6161
.map_or(false, |a| self == a)
6262
}
6363

64-
fn cloned(&self) -> Box<dyn Packet> {
64+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
6565
Box::new(self.clone())
6666
}
6767
}

src/payload_feedbacks/receiver_estimated_maximum_bitrate/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ impl Packet for ReceiverEstimatedMaximumBitrate {
7676
self
7777
}
7878

79-
fn equal(&self, other: &dyn Packet) -> bool {
79+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
8080
other
8181
.as_any()
8282
.downcast_ref::<ReceiverEstimatedMaximumBitrate>()
8383
.map_or(false, |a| self == a)
8484
}
8585

86-
fn cloned(&self) -> Box<dyn Packet> {
86+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
8787
Box::new(self.clone())
8888
}
8989
}

src/payload_feedbacks/slice_loss_indication/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ impl Packet for SliceLossIndication {
6969
self
7070
}
7171

72-
fn equal(&self, other: &dyn Packet) -> bool {
72+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
7373
other
7474
.as_any()
7575
.downcast_ref::<SliceLossIndication>()
7676
.map_or(false, |a| self == a)
7777
}
7878

79-
fn cloned(&self) -> Box<dyn Packet> {
79+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
8080
Box::new(self.clone())
8181
}
8282
}

src/raw_packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ impl Packet for RawPacket {
4040
self
4141
}
4242

43-
fn equal(&self, other: &dyn Packet) -> bool {
43+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
4444
other
4545
.as_any()
4646
.downcast_ref::<RawPacket>()
4747
.map_or(false, |a| self == a)
4848
}
4949

50-
fn cloned(&self) -> Box<dyn Packet> {
50+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
5151
Box::new(self.clone())
5252
}
5353
}

src/receiver_report/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ impl Packet for ReceiverReport {
7373
self
7474
}
7575

76-
fn equal(&self, other: &dyn Packet) -> bool {
76+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
7777
other
7878
.as_any()
7979
.downcast_ref::<ReceiverReport>()
8080
.map_or(false, |a| self == a)
8181
}
8282

83-
fn cloned(&self) -> Box<dyn Packet> {
83+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
8484
Box::new(self.clone())
8585
}
8686
}

src/reception_report.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ impl Packet for ReceptionReport {
7070
self
7171
}
7272

73-
fn equal(&self, other: &dyn Packet) -> bool {
73+
fn equal(&self, other: &(dyn Packet + Send + Sync)) -> bool {
7474
other
7575
.as_any()
7676
.downcast_ref::<ReceptionReport>()
7777
.map_or(false, |a| self == a)
7878
}
7979

80-
fn cloned(&self) -> Box<dyn Packet> {
80+
fn cloned(&self) -> Box<dyn Packet + Send + Sync> {
8181
Box::new(self.clone())
8282
}
8383
}

0 commit comments

Comments
 (0)