Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
- Added `#[allow(dead_code)]` attribute to `ChannelReadCallback` in `channel_read_fn.rs`
- Modified and added test cases in `webrtc_server.rs`
- Made changes to the `Producer` struct and related functions in `producer.rs`
- Made updates to the `ScalabilityMode` implementation in `scalability_modes.rs`
- Implemented various functions and callbacks in `router.rs`
- Made modifications and fixes in `ortc/tests.rs`
- Updated test cases in `webrtc_transport.rs`
- Added attributes to struct definitions in `channel_write_fn.rs` and `consumer.rs`
- Modified the code in `worker/build.rs`
  • Loading branch information
dhilipsiva committed Jun 22, 2024
1 parent abd5552 commit 725cd2d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 38 deletions.
28 changes: 14 additions & 14 deletions rust/src/ortc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
]
);

assert_eq!(rtp_mapping.encodings.get(0).unwrap().ssrc, Some(11111111));
assert_eq!(rtp_mapping.encodings.get(0).unwrap().rid, None);
assert_eq!(rtp_mapping.encodings.first().unwrap().ssrc, Some(11111111));
assert_eq!(rtp_mapping.encodings.first().unwrap().rid, None);
assert_eq!(rtp_mapping.encodings.get(1).unwrap().ssrc, Some(21111111));
assert_eq!(rtp_mapping.encodings.get(1).unwrap().rid, None);
assert_eq!(rtp_mapping.encodings.get(2).unwrap().ssrc, None);
Expand Down Expand Up @@ -303,21 +303,21 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
);

assert_eq!(
consumable_rtp_parameters.encodings.get(0).unwrap().ssrc,
Some(rtp_mapping.encodings.get(0).unwrap().mapped_ssrc),
consumable_rtp_parameters.encodings.first().unwrap().ssrc,
Some(rtp_mapping.encodings.first().unwrap().mapped_ssrc),
);
assert_eq!(
consumable_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.max_bitrate,
Some(111111),
);
assert_eq!(
consumable_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.scalability_mode,
ScalabilityMode::L1T3,
Expand Down Expand Up @@ -489,28 +489,28 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
assert_eq!(consumer_rtp_parameters.encodings.len(), 1);
assert!(consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.ssrc
.is_some());
assert!(consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.rtx
.is_some());
assert_eq!(
consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.scalability_mode,
ScalabilityMode::L3T3,
);
assert_eq!(
consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.max_bitrate,
Some(333333),
Expand Down Expand Up @@ -566,26 +566,26 @@ fn get_producer_rtp_parameters_mapping_get_consumable_rtp_parameters_get_consume
assert_eq!(pipe_consumer_rtp_parameters.encodings.len(), 3);
assert!(pipe_consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.ssrc
.is_some());
assert!(pipe_consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.rtx
.is_none());
assert!(pipe_consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.max_bitrate
.is_some());
assert_eq!(
pipe_consumer_rtp_parameters
.encodings
.get(0)
.first()
.unwrap()
.scalability_mode,
ScalabilityMode::L1T3,
Expand Down
8 changes: 6 additions & 2 deletions rust/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,12 @@ impl Router {
// We've created `DataConsumer` with SCTP above, so this should never panic
pipe_data_consumer.sctp_stream_parameters().unwrap(),
);
producer_options.label = pipe_data_consumer.label().clone();
producer_options.protocol = pipe_data_consumer.protocol().clone();
producer_options
.label
.clone_from(pipe_data_consumer.label());
producer_options
.protocol
.clone_from(pipe_data_consumer.protocol());
producer_options.app_data = data_producer.app_data().clone();

producer_options
Expand Down
2 changes: 1 addition & 1 deletion rust/src/router/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ impl Producer {
match Notification::from_fbs(notification) {
Ok(notification) => match notification {
Notification::Score(scores) => {
*score.lock() = scores.clone();
score.lock().clone_from(&scores);
handlers.score.call(|callback| {
callback(&scores);
});
Expand Down
6 changes: 3 additions & 3 deletions rust/src/scalability_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ impl FromStr for ScalabilityMode {
}
}

impl ToString for ScalabilityMode {
fn to_string(&self) -> String {
self.as_str().to_string()
impl std::fmt::Display for ScalabilityMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}

Expand Down
1 change: 1 addition & 0 deletions rust/src/worker/utils/channel_read_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ unsafe extern "C" fn free_vec(message: *mut u8, message_len: u32, message_capaci
Vec::from_raw_parts(message, message_len as usize, message_capacity);
}

#[allow(dead_code)]
pub(super) struct ChannelReadCallback(
Box<dyn (FnMut(UvAsyncT) -> Option<Vec<u8>>) + Send + 'static>,
);
Expand Down
1 change: 1 addition & 0 deletions rust/src/worker/utils/channel_write_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::os::raw::c_void;
use std::slice;

#[allow(clippy::type_complexity)]
#[allow(dead_code)]
pub(super) struct ChannelReadCallback(Box<dyn FnMut(&[u8]) + Send + 'static>);

pub(crate) struct PreparedChannelWrite {
Expand Down
11 changes: 6 additions & 5 deletions rust/tests/integration/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn consumer_device_capabilities() -> RtpCapabilities {
}

// Keeps executor threads running until dropped
#[allow(dead_code)]
struct ExecutorGuard(Vec<async_oneshot::Sender<()>>);

fn create_executor() -> (ExecutorGuard, Arc<Executor<'static>>) {
Expand Down Expand Up @@ -977,7 +978,7 @@ fn dump_succeeds() {
ssrc: audio_consumer
.rtp_parameters()
.encodings
.get(0)
.first()
.unwrap()
.ssrc,
rid: None,
Expand Down Expand Up @@ -1086,13 +1087,13 @@ fn dump_succeeds() {
ssrc: video_consumer
.rtp_parameters()
.encodings
.get(0)
.first()
.unwrap()
.ssrc,
rtx: video_consumer
.rtp_parameters()
.encodings
.get(0)
.first()
.unwrap()
.rtx,
dtx: None,
Expand Down Expand Up @@ -1165,7 +1166,7 @@ fn get_stats_succeeds() {
audio_consumer
.rtp_parameters()
.encodings
.get(0)
.first()
.unwrap()
.ssrc
.unwrap()
Expand Down Expand Up @@ -1214,7 +1215,7 @@ fn get_stats_succeeds() {
video_consumer
.rtp_parameters()
.encodings
.get(0)
.first()
.unwrap()
.ssrc
.unwrap()
Expand Down
8 changes: 4 additions & 4 deletions rust/tests/integration/webrtc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ fn unavailable_infos_fails() {
})
.detach();

#[derive(Debug, PartialEq)]
struct CustomAppData {
foo: u32,
}
// #[derive(Debug, PartialEq)]
// struct CustomAppData {
// foo: u32,
// }

// Using an unavailable listen IP.
{
Expand Down
6 changes: 3 additions & 3 deletions rust/tests/integration/webrtc_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn create_with_fixed_port_succeeds() {
.await
.expect("Failed to create WebRTC transport");

assert_eq!(transport.ice_candidates().get(0).unwrap().port, port);
assert_eq!(transport.ice_candidates().first().unwrap().port, port);
});
}

Expand All @@ -306,7 +306,7 @@ fn create_with_port_range_succeeds() {
.await
.expect("Failed to create WebRTC transport");

let port1 = transport1.ice_candidates().get(0).unwrap().port;
let port1 = transport1.ice_candidates().first().unwrap().port;
assert!(port1 >= *port_range.start() && port1 <= *port_range.end());

let transport2 = router
Expand All @@ -325,7 +325,7 @@ fn create_with_port_range_succeeds() {
.await
.expect("Failed to create WebRTC transport");

let port2 = transport2.ice_candidates().get(0).unwrap().port;
let port2 = transport2.ice_candidates().first().unwrap().port;
assert!(port2 >= *port_range.start() && port2 <= *port_range.end());

assert!(matches!(
Expand Down
13 changes: 7 additions & 6 deletions worker/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ fn main() {
)
.expect("Failed to translate flatbuffers files");

fs::write(
format!("{out_dir}/fbs.rs"),
planus_codegen::generate_rust(&flatbuffers_declarations)
.expect("Failed to generate Rust code from flatbuffers"),
)
.expect("Failed to write generated Rust flatbuffers into fbs.rs");
let planus_content = planus_codegen::generate_rust(&flatbuffers_declarations)
.expect("Failed to generate Rust code from flatbuffers");

let planus_content =
planus_content.replace("mod root {", "mod root {\n #![allow(clippy::all)]");
fs::write(format!("{out_dir}/fbs.rs"), planus_content)
.expect("Failed to write generated Rust flatbuffers into fbs.rs");

if env::var("DOCS_RS").is_ok() {
// Skip everything when building docs on docs.rs
Expand Down

0 comments on commit 725cd2d

Please sign in to comment.