Skip to content

Commit 3a27093

Browse files
authored
enable lints from workspace for puffin_http (#238)
### Checklist * [X] I have read the [Contributor Guide](../CONTRIBUTING.md) * [X] I have read and agree to the [Code of Conduct](../CODE_OF_CONDUCT.md) * [X] I have added a description of my changes and why I'd like them included in the section below ### Description of Changes Enable lints from workspace for `puffin_http` and fix the report from lints. ### Related Issues No related issue.
1 parent 3f73b4f commit 3a27093

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

puffin_http/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ puffin = { version = "0.19.1", path = "../puffin", features = [
2727
[dev-dependencies]
2828
simple_logger = "4.2"
2929
paste = "1.0.15"
30+
31+
[lints]
32+
workspace = true

puffin_http/examples/server.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[expect(clippy::unwrap_used)]
2+
#[expect(clippy::print_stderr)]
3+
#[expect(clippy::infinite_loop)]
14
fn main() {
25
simple_logger::SimpleLogger::new()
36
.with_level(log::LevelFilter::Info)
@@ -28,7 +31,7 @@ fn main() {
2831
sleep_ms(14);
2932
if frame_counter % 7 == 0 {
3033
puffin::profile_scope!("Spike");
31-
std::thread::sleep(std::time::Duration::from_millis(10))
34+
std::thread::sleep(std::time::Duration::from_millis(10));
3235
}
3336

3437
for _ in 0..1000 {

puffin_http/src/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ impl Client {
4444
frame_view: frame_view.clone(),
4545
};
4646

47-
let _ = std::thread::Builder::new()
48-
.name("http_client_thread".to_string())
47+
let _: std::thread::JoinHandle<()> = std::thread::Builder::new()
48+
.name("http_client_thread".to_owned())
4949
.spawn(move || {
5050
log::info!("Connecting to {}…", addr);
5151
while alive.load(SeqCst) {
@@ -78,7 +78,8 @@ impl Client {
7878
}
7979
}
8080
}
81-
});
81+
})
82+
.expect("Failed to spawn client thread");
8283

8384
client
8485
}

puffin_http/src/server.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Context as _;
22
use puffin::{FrameSinkId, GlobalProfiler, ScopeCollection};
33
use std::{
4-
io::Write,
4+
io::Write as _,
55
net::{SocketAddr, TcpListener, TcpStream},
66
sync::{
77
Arc,
@@ -27,7 +27,11 @@ pub struct Server {
2727
impl Server {
2828
/// Start listening for connections on this addr (e.g. "0.0.0.0:8585")
2929
///
30-
/// Connects to the [GlobalProfiler]
30+
/// Connects to the [`GlobalProfiler`]
31+
///
32+
/// # Errors
33+
///
34+
/// forward error from [`Self::new_custom`] call.
3135
pub fn new(bind_addr: &str) -> anyhow::Result<Self> {
3236
fn global_add(sink: puffin::FrameSink) -> FrameSinkId {
3337
GlobalProfiler::lock().add_sink(sink)
@@ -47,7 +51,7 @@ impl Server {
4751
/// * `sink_install` - A function that installs the [Server]'s sink into
4852
/// a [`GlobalProfiler`], and then returns the [`FrameSinkId`] so that the sink can be removed later
4953
/// * `sink_remove` - A function that reverts `sink_install`.
50-
/// This should be a call to remove the sink from the profiler ([GlobalProfiler::remove_sink])
54+
/// This should be a call to remove the sink from the profiler ([`GlobalProfiler::remove_sink`])
5155
///
5256
/// # Example
5357
///
@@ -56,6 +60,11 @@ impl Server {
5660
/// instance for the main UI loop, and another for the background worker loop, and events/frames from those thread(s)
5761
/// would be completely separated. You can then hook up two separate instances of `puffin_viewer` and profile them separately.
5862
///
63+
/// # Errors
64+
///
65+
/// Will return an `io::Error` if the [`TcpListener::bind`] fail.
66+
/// Will return an `io::Error` if the spawn of the thread ,for connection and data send management, fail.
67+
///
5968
/// ## Per-Thread Profiling
6069
/// ```
6170
/// # use puffin::GlobalProfiler;
@@ -269,7 +278,7 @@ impl Server {
269278
tx.send(frame).ok();
270279
}));
271280

272-
Ok(Server {
281+
Ok(Self {
273282
sink_id,
274283
join_handle: Some(join_handle),
275284
num_clients,
@@ -380,7 +389,7 @@ impl PuffinServerImpl {
380389

381390
packet
382391
.write_all(&crate::PROTOCOL_VERSION.to_le_bytes())
383-
.unwrap();
392+
.context("Encode puffin `PROTOCOL_VERSION` in packet to be send to client.")?;
384393

385394
let scope_collection = if self.send_all_scopes {
386395
Some(&self.scope_collection)
@@ -415,6 +424,7 @@ impl PuffinServerImpl {
415424
}
416425
}
417426

427+
#[expect(clippy::needless_pass_by_value)]
418428
fn client_loop(
419429
packet_rx: crossbeam_channel::Receiver<Packet>,
420430
client_addr: SocketAddr,

0 commit comments

Comments
 (0)