Re: [PATCH net-next] rust: net::phy inline if expressions to improve read_status

From: Andrew Lunn

Date: Fri Sep 19 2025 - 11:17:09 EST


> There's obviously nothing wrong with local variables. This patch is not
> about performance improvements, but writing consistent and idiomatic
> Rust code.
>
> Currently, dev.set_duplex() uses a local variable and is called once,
> whereas dev.set_speed() doesn't use a local variable and is called
> twice.

I would suggest the opposite change if you want to make the code
consistent:

let speed = if ret & BMCR_SPEED100 != 0 {
uapi::SPEED_100
} else {
uapi::SPEED_10
}
dev.set_speed(speed)

Andrew