Skip to content

Commit 813e3ca

Browse files
authored
make clippy happy (#274)
1 parent 74f3e12 commit 813e3ca

File tree

23 files changed

+55
-68
lines changed

23 files changed

+55
-68
lines changed

mitmproxy-contentviews/src/protobuf/existing_proto_definitions.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,12 @@ fn walk_proto_directory(definitions_path: &Path, parser: &mut Parser) -> anyhow:
169169
for entry in definitions_path
170170
.read_dir()
171171
.context("failed to read protobuf directory")?
172+
.flatten()
172173
{
173-
if let Ok(entry) = entry {
174-
if entry.metadata()?.is_dir() {
175-
walk_proto_directory(entry.path().as_path(), parser)?;
176-
} else if entry.file_name().to_string_lossy().ends_with(".proto") {
177-
parser.input(entry.path());
178-
}
174+
if entry.metadata()?.is_dir() {
175+
walk_proto_directory(entry.path().as_path(), parser)?;
176+
} else if entry.file_name().to_string_lossy().ends_with(".proto") {
177+
parser.input(entry.path());
179178
}
180179
}
181180
Ok(())

mitmproxy-contentviews/src/protobuf/raw_to_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn create_descriptor_proto(
111111
}
112112

113113
for (field_index, field_values) in field_groups.into_iter() {
114-
let name = Some(format!("unknown_field_{}", field_index));
114+
let name = Some(format!("unknown_field_{field_index}"));
115115
let mut add_int = |name: Option<String>, typ: Type| {
116116
descriptor.field.push(FieldDescriptorProto {
117117
number: Some(field_index as i32),

mitmproxy-contentviews/src/protobuf/yaml_to_pretty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ impl Display for NumReprs {
2929
.unwrap();
3030
let mut i = self.0.iter().filter(|(t, _)| t != min_typ);
3131

32-
write!(f, "{}", min_val)?;
32+
write!(f, "{min_val}")?;
3333
if let Some((t, v)) = i.next() {
34-
write!(f, " # {}: {}", t, v)?;
34+
write!(f, " # {t}: {v}")?;
3535
}
3636
for (t, v) in i {
37-
write!(f, ", {}: {}", t, v)?;
37+
write!(f, ", {t}: {v}")?;
3838
}
3939
Ok(())
4040
}
@@ -95,7 +95,7 @@ pub(super) fn apply_replacements(yaml_str: &str) -> anyhow::Result<String> {
9595

9696
/// Ensure that floating point numbers have a ".0" component so that we roundtrip.
9797
fn format_float<T: Display>(val: T) -> String {
98-
let mut ret = format!("{:.}", val);
98+
let mut ret = format!("{val:.}");
9999
if !ret.contains(".") {
100100
ret.push_str(".0");
101101
}

mitmproxy-rs/src/contentviews.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Contentview {
107107
pub fn prettify(&self, data: Vec<u8>, metadata: PythonMetadata) -> PyResult<String> {
108108
self.0
109109
.prettify(&data, &metadata)
110-
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))
110+
.map_err(|e| PyValueError::new_err(format!("{e:?}")))
111111
}
112112

113113
/// Return the priority of this view for rendering data.
@@ -153,7 +153,7 @@ impl InteractiveContentview {
153153
pub fn reencode(&self, data: &str, metadata: PythonMetadata) -> PyResult<Vec<u8>> {
154154
self.0
155155
.reencode(data, &metadata)
156-
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))
156+
.map_err(|e| PyValueError::new_err(format!("{e:?}")))
157157
}
158158

159159
fn __repr__(self_: PyRef<'_, Self>) -> PyResult<String> {

mitmproxy-rs/src/dns_resolver.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ impl DnsResolver {
2626
let resolver =
2727
mitmproxy::dns::DnsResolver::new(name_servers, use_hosts_file).map_err(|e| {
2828
pyo3::exceptions::PyRuntimeError::new_err(format!(
29-
"failed to create dns resolver: {}",
30-
e
29+
"failed to create dns resolver: {e}"
3130
))
3231
})?;
3332
Ok(Self(Arc::new(resolver)))
@@ -74,7 +73,7 @@ impl DnsResolver {
7473
#[pyfunction]
7574
pub fn get_system_dns_servers() -> PyResult<Vec<String>> {
7675
DNS_SERVERS.clone().map_err(|e| {
77-
pyo3::exceptions::PyRuntimeError::new_err(format!("failed to get dns servers: {}", e))
76+
pyo3::exceptions::PyRuntimeError::new_err(format!("failed to get dns servers: {e}"))
7877
})
7978
}
8079

mitmproxy-rs/src/process_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn active_executables() -> PyResult<Vec<Process>> {
5757
{
5858
processes::active_executables()
5959
.map(|p| p.into_iter().map(Process).collect())
60-
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(format!("{}", e)))
60+
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(format!("{e}")))
6161
}
6262
#[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
6363
Err(pyo3::exceptions::PyNotImplementedError::new_err(

mitmproxy-rs/src/server/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Server {
4545
T: PacketSourceConf,
4646
{
4747
let typ = packet_source_conf.name();
48-
log::debug!("Initializing {} ...", typ);
48+
log::debug!("Initializing {typ} ...");
4949

5050
// Channel used to notify Python land of incoming connections.
5151
let (transport_events_tx, transport_events_rx) = mpsc::channel(256);
@@ -80,7 +80,7 @@ impl Server {
8080
let (shutdown_done_tx, shutdown_done_rx) = shutdown::channel();
8181
tokio::spawn(shutdown_task(tasks, shutdown_done_tx));
8282

83-
log::debug!("{} successfully initialized.", typ);
83+
log::debug!("{typ} successfully initialized.");
8484

8585
Ok((
8686
Server {

mitmproxy-rs/src/server/local_redirector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl LocalRedirector {
3939
fn describe_spec(spec: &str) -> PyResult<String> {
4040
InterceptConf::try_from(spec)
4141
.map(|conf| conf.description())
42-
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))
42+
.map_err(|e| PyValueError::new_err(format!("{e:?}")))
4343
}
4444

4545
/// Set a new intercept spec.

mitmproxy-rs/src/syntax_highlight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn highlight(text: String, language: &str) -> PyResult<Vec<(&'static str, St
2525
.map(|(tag, text)| (tag.as_str(), text))
2626
.collect()
2727
})
28-
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))
28+
.map_err(|e| PyValueError::new_err(format!("{e:?}")))
2929
}
3030

3131
/// Return the list of all possible syntax highlight tags.

mitmproxy-rs/src/task.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl PyInteropTask {
101101
if let Err(err) = future.await {
102102
let is_cancelled = Python::with_gil(|py| err.is_instance_of::<CancelledError>(py));
103103
if !is_cancelled {
104-
log::error!("TCP connection handler coroutine raised an exception:\n{}", err);
104+
log::error!("TCP connection handler coroutine raised an exception:\n{err}");
105105
}
106106
}
107107
active_streams.lock().await.remove(&connection_id);
@@ -112,7 +112,7 @@ impl PyInteropTask {
112112

113113
Ok(())
114114
}) {
115-
log::error!("Failed to spawn connection handler:\n{}", err);
115+
log::error!("Failed to spawn connection handler:\n{err}");
116116
};
117117
},
118118
}
@@ -127,10 +127,7 @@ impl PyInteropTask {
127127
// Future is already finished: just await;
128128
// Python exceptions are already logged by the wrapper coroutine
129129
if let Err(err) = handle.await {
130-
log::warn!(
131-
"TCP connection handler coroutine could not be joined: {}",
132-
err
133-
);
130+
log::warn!("TCP connection handler coroutine could not be joined: {err}");
134131
}
135132
} else {
136133
// Future is not finished: abort tokio task
@@ -139,7 +136,7 @@ impl PyInteropTask {
139136
if let Err(err) = handle.await {
140137
if !err.is_cancelled() {
141138
// JoinError was not caused by cancellation: coroutine panicked, log error
142-
log::error!("TCP connection handler coroutine panicked: {}", err);
139+
log::error!("TCP connection handler coroutine panicked: {err}");
143140
}
144141
}
145142
}

0 commit comments

Comments
 (0)