Skip to content

Commit 777bae9

Browse files
authored
Merge pull request #10 from xnorpx/xnorpx/clippy
Clippys and rust analyzer warnings.
2 parents 17dab22 + 8d70d29 commit 777bae9

37 files changed

+125
-219
lines changed

src/association/association_test.rs

+32-20
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ fn create_association(config: TransportConfig) -> Association {
1616

1717
#[test]
1818
fn test_create_forward_tsn_forward_one_abandoned() -> Result<()> {
19-
let mut a = Association::default();
19+
let mut a = Association {
20+
cumulative_tsn_ack_point: 9,
21+
advanced_peer_tsn_ack_point: 10,
22+
..Default::default()
23+
};
2024

21-
a.cumulative_tsn_ack_point = 9;
22-
a.advanced_peer_tsn_ack_point = 10;
2325
a.inflight_queue.push_no_check(ChunkPayloadData {
2426
beginning_fragment: true,
2527
ending_fragment: true,
@@ -44,10 +46,12 @@ fn test_create_forward_tsn_forward_one_abandoned() -> Result<()> {
4446

4547
#[test]
4648
fn test_create_forward_tsn_forward_two_abandoned_with_the_same_si() -> Result<()> {
47-
let mut a = Association::default();
49+
let mut a = Association {
50+
cumulative_tsn_ack_point: 9,
51+
advanced_peer_tsn_ack_point: 12,
52+
..Default::default()
53+
};
4854

49-
a.cumulative_tsn_ack_point = 9;
50-
a.advanced_peer_tsn_ack_point = 12;
5155
a.inflight_queue.push_no_check(ChunkPayloadData {
5256
beginning_fragment: true,
5357
ending_fragment: true,
@@ -99,7 +103,7 @@ fn test_create_forward_tsn_forward_two_abandoned_with_the_same_si() -> Result<()
99103
assert_eq!(1, s.sequence, "ssn should be 1");
100104
si2ok = true;
101105
}
102-
_ => assert!(false, "unexpected stream indentifier"),
106+
_ => panic!("unexpected stream indentifier"),
103107
}
104108
}
105109
assert!(si1ok, "si=1 should be present");
@@ -110,9 +114,11 @@ fn test_create_forward_tsn_forward_two_abandoned_with_the_same_si() -> Result<()
110114

111115
#[test]
112116
fn test_handle_forward_tsn_forward_3unreceived_chunks() -> Result<()> {
113-
let mut a = Association::default();
117+
let mut a = Association {
118+
use_forward_tsn: true,
119+
..Default::default()
120+
};
114121

115-
a.use_forward_tsn = true;
116122
let prev_tsn = a.peer_last_tsn;
117123

118124
let fwdtsn = ChunkForwardTsn {
@@ -144,9 +150,11 @@ fn test_handle_forward_tsn_forward_3unreceived_chunks() -> Result<()> {
144150

145151
#[test]
146152
fn test_handle_forward_tsn_forward_1for1_missing() -> Result<()> {
147-
let mut a = Association::default();
153+
let mut a = Association {
154+
use_forward_tsn: true,
155+
..Default::default()
156+
};
148157

149-
a.use_forward_tsn = true;
150158
let prev_tsn = a.peer_last_tsn;
151159

152160
// this chunk is blocked by the missing chunk at tsn=1
@@ -192,7 +200,10 @@ fn test_handle_forward_tsn_forward_1for1_missing() -> Result<()> {
192200

193201
#[test]
194202
fn test_handle_forward_tsn_forward_1for2_missing() -> Result<()> {
195-
let mut a = Association::default();
203+
let mut a = Association {
204+
use_forward_tsn: true,
205+
..Default::default()
206+
};
196207

197208
a.use_forward_tsn = true;
198209
let prev_tsn = a.peer_last_tsn;
@@ -238,9 +249,11 @@ fn test_handle_forward_tsn_forward_1for2_missing() -> Result<()> {
238249

239250
#[test]
240251
fn test_handle_forward_tsn_dup_forward_tsn_chunk_should_generate_sack() -> Result<()> {
241-
let mut a = Association::default();
252+
let mut a = Association {
253+
use_forward_tsn: true,
254+
..Default::default()
255+
};
242256

243-
a.use_forward_tsn = true;
244257
let prev_tsn = a.peer_last_tsn;
245258

246259
let fwdtsn = ChunkForwardTsn {
@@ -270,8 +283,7 @@ fn test_assoc_create_new_stream() -> Result<()> {
270283
if let Some(s) = a.create_stream(i as u16, true, PayloadProtocolIdentifier::Unknown) {
271284
s.stream_identifier
272285
} else {
273-
assert!(false, "{} should success", i);
274-
0
286+
panic!("{} should success", i);
275287
};
276288
let result = a.streams.get(&stream_identifier);
277289
assert!(result.is_some(), "should be in a.streams map");
@@ -406,7 +418,7 @@ fn test_assoc_max_message_size_default() -> Result<()> {
406418
"should be not Error::ErrOutboundPacketTooLarge"
407419
);
408420
} else {
409-
assert!(false, "should be error");
421+
panic!("should be error");
410422
}
411423

412424
if let Err(err) = s.write_sctp(&p.slice(..65537), ppi) {
@@ -416,7 +428,7 @@ fn test_assoc_max_message_size_default() -> Result<()> {
416428
"should be Error::ErrOutboundPacketTooLarge"
417429
);
418430
} else {
419-
assert!(false, "should be error");
431+
panic!("should be error");
420432
}
421433
}
422434

@@ -443,7 +455,7 @@ fn test_assoc_max_message_size_explicit() -> Result<()> {
443455
"should be not Error::ErrOutboundPacketTooLarge"
444456
);
445457
} else {
446-
assert!(false, "should be error");
458+
panic!("should be error");
447459
}
448460

449461
if let Err(err) = s.write_sctp(&p.slice(..30001), ppi) {
@@ -453,7 +465,7 @@ fn test_assoc_max_message_size_explicit() -> Result<()> {
453465
"should be Error::ErrOutboundPacketTooLarge"
454466
);
455467
} else {
456-
assert!(false, "should be error");
468+
panic!("should be error");
457469
}
458470
}
459471

src/association/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,6 @@ impl Association {
18891889
reconfig_response_sequence_number: p.reconfig_request_sequence_number,
18901890
sender_last_tsn: tsn,
18911891
stream_identifiers: sis_to_reset,
1892-
..Default::default()
18931892
})),
18941893
..Default::default()
18951894
};

src/association/state.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::fmt;
22

33
/// association state enums
4-
#[derive(Debug, Copy, Clone, PartialEq)]
4+
#[derive(Debug, Copy, Clone, PartialEq, Default)]
55
pub(crate) enum AssociationState {
6+
#[default]
67
Closed = 0,
78
CookieWait = 1,
89
CookieEchoed = 2,
@@ -13,12 +14,6 @@ pub(crate) enum AssociationState {
1314
ShutdownSent = 7,
1415
}
1516

16-
impl Default for AssociationState {
17-
fn default() -> Self {
18-
AssociationState::Closed
19-
}
20-
}
21-
2217
impl From<u8> for AssociationState {
2318
fn from(v: u8) -> AssociationState {
2419
match v {
@@ -63,17 +58,13 @@ impl AssociationState {
6358
}
6459

6560
/// ack mode (for testing)
66-
#[derive(Debug, Copy, Clone, PartialEq)]
61+
#[derive(Debug, Copy, Clone, PartialEq, Default)]
6762
pub(crate) enum AckMode {
63+
#[default]
6864
Normal,
6965
NoDelay,
7066
AlwaysDelay,
7167
}
72-
impl Default for AckMode {
73-
fn default() -> Self {
74-
AckMode::Normal
75-
}
76-
}
7768

7869
impl fmt::Display for AckMode {
7970
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -87,19 +78,14 @@ impl fmt::Display for AckMode {
8778
}
8879

8980
/// ack transmission state
90-
#[derive(Debug, Copy, Clone, PartialEq)]
81+
#[derive(Debug, Copy, Clone, PartialEq, Default)]
9182
pub(crate) enum AckState {
92-
Idle, // ack timer is off
83+
#[default]
84+
Idle, // ack timer is off
9385
Immediate, // will send ack immediately
9486
Delay, // ack timer is on (ack is being delayed)
9587
}
9688

97-
impl Default for AckState {
98-
fn default() -> Self {
99-
AckState::Idle
100-
}
101-
}
102-
10389
impl fmt::Display for AckState {
10490
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10591
let s = match *self {

src/association/stream.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,17 @@ pub enum StreamEvent {
5252
}
5353

5454
/// Reliability type for stream
55-
#[derive(Debug, Copy, Clone, PartialEq)]
55+
#[derive(Debug, Copy, Clone, PartialEq, Default)]
5656
pub enum ReliabilityType {
5757
/// ReliabilityTypeReliable is used for reliable transmission
58+
#[default]
5859
Reliable = 0,
5960
/// ReliabilityTypeRexmit is used for partial reliability by retransmission count
6061
Rexmit = 1,
6162
/// ReliabilityTypeTimed is used for partial reliability by retransmission duration
6263
Timed = 2,
6364
}
6465

65-
impl Default for ReliabilityType {
66-
fn default() -> Self {
67-
ReliabilityType::Reliable
68-
}
69-
}
70-
7166
impl fmt::Display for ReliabilityType {
7267
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7368
let s = match *self {
@@ -319,8 +314,9 @@ impl<'a> Stream<'a> {
319314
}
320315
}
321316

322-
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
317+
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
323318
pub enum RecvSendState {
319+
#[default]
324320
Closed = 0,
325321
Readable = 1,
326322
Writable = 2,
@@ -338,12 +334,6 @@ impl From<u8> for RecvSendState {
338334
}
339335
}
340336

341-
impl Default for RecvSendState {
342-
fn default() -> Self {
343-
RecvSendState::Closed
344-
}
345-
}
346-
347337
/// StreamState represents the state of an SCTP stream
348338
#[derive(Default, Debug)]
349339
pub struct StreamState {

src/chunk/chunk_abort.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Bytes, BytesMut};
4-
use std::fmt;
5-
63
///Abort represents an SCTP Chunk of type ABORT
74
///
85
///The ABORT chunk is sent to the peer of an association to close the

src/chunk/chunk_cookie_ack.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Bytes, BytesMut};
4-
use std::fmt;
5-
63
/// chunkCookieAck represents an SCTP Chunk of type chunkCookieAck
74
///
85
/// 0 1 2 3

src/chunk/chunk_cookie_echo.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Bytes, BytesMut};
4-
use std::fmt;
5-
63
/// CookieEcho represents an SCTP Chunk of type CookieEcho
74
///
85
/// 0 1 2 3

src/chunk/chunk_error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Bytes, BytesMut};
4-
use std::fmt;
5-
63
///Operation Error (ERROR) (9)
74
///
85
///An endpoint sends this chunk to its peer endpoint to notify it of

src/chunk/chunk_forward_tsn.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Buf, BufMut, Bytes, BytesMut};
4-
use std::fmt;
5-
63
///This chunk shall be used by the data sender to inform the data
74
///receiver to adjust its cumulative received TSN point forward because
85
///some missing TSNs are associated with data chunks that SHOULD NOT be

src/chunk/chunk_header.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_type::*, *};
22

3-
use bytes::{Buf, BufMut, Bytes, BytesMut};
4-
use std::fmt;
5-
63
///chunkHeader represents a SCTP Chunk header, defined in https://tools.ietf.org/html/rfc4960#section-3.2
74
///The figure below illustrates the field format for the chunks to be
85
///transmitted in the SCTP packet. Each chunk is formatted with a Chunk

src/chunk/chunk_heartbeat.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22
use crate::param::{param_header::*, param_type::*, *};
33

4-
use bytes::{Bytes, BytesMut};
5-
use std::fmt;
6-
74
///chunkHeartbeat represents an SCTP Chunk of type HEARTBEAT
85
///
96
///An endpoint should send this chunk to its peer endpoint to probe the

src/chunk/chunk_heartbeat_ack.rs

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use crate::param::param_type::ParamType;
33
use crate::param::{param_header::*, *};
44
use crate::util::get_padding_size;
55

6-
use bytes::{Bytes, BytesMut};
7-
use std::fmt;
8-
96
///chunkHeartbeatAck represents an SCTP Chunk of type HEARTBEAT ACK
107
///
118
///An endpoint should send this chunk to its peer endpoint as a response

src/chunk/chunk_init.rs

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ use crate::param::param_supported_extensions::ParamSupportedExtensions;
33
use crate::param::{param_header::*, *};
44
use crate::util::get_padding_size;
55

6-
use bytes::{Buf, BufMut, Bytes, BytesMut};
7-
use std::fmt;
8-
96
///chunkInitCommon represents an SCTP Chunk body of type INIT and INIT ACK
107
///
118
/// 0 1 2 3

src/chunk/chunk_payload_data.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Buf, BufMut, Bytes, BytesMut};
4-
use std::fmt;
53
use std::time::Instant;
64

75
pub(crate) const PAYLOAD_DATA_ENDING_FRAGMENT_BITMASK: u8 = 1;
@@ -15,21 +13,17 @@ pub(crate) const PAYLOAD_DATA_HEADER_SIZE: usize = 12;
1513
// <https://www.iana.org/assignments/sctp-parameters/sctp-parameters.xhtml#sctp-parameters-25>
1614
#[derive(Debug, Copy, Clone, PartialEq)]
1715
#[repr(C)]
16+
#[derive(Default)]
1817
pub enum PayloadProtocolIdentifier {
1918
Dcep = 50,
2019
String = 51,
2120
Binary = 53,
2221
StringEmpty = 56,
2322
BinaryEmpty = 57,
23+
#[default]
2424
Unknown,
2525
}
2626

27-
impl Default for PayloadProtocolIdentifier {
28-
fn default() -> Self {
29-
PayloadProtocolIdentifier::Unknown
30-
}
31-
}
32-
3327
impl fmt::Display for PayloadProtocolIdentifier {
3428
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3529
let s = match *self {

src/chunk/chunk_reconfig.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ use super::{chunk_header::*, chunk_type::*, *};
22
use crate::param::{param_header::*, *};
33
use crate::util::get_padding_size;
44

5-
use bytes::{Bytes, BytesMut};
6-
use std::fmt;
7-
85
///https://tools.ietf.org/html/rfc6525#section-3.1
96
///chunkReconfig represents an SCTP Chunk used to reconfigure streams.
107
///

src/chunk/chunk_selective_ack.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use super::{chunk_header::*, chunk_type::*, *};
22

3-
use bytes::{Buf, BufMut, Bytes, BytesMut};
4-
use std::fmt;
5-
63
///chunkSelectiveAck represents an SCTP Chunk of type SACK
74
///
85
///This chunk is sent to the peer endpoint to acknowledge received DATA

0 commit comments

Comments
 (0)