Question Details

No question body available.

Tags

rust

Answers (6)

March 10, 2026 Score: 2 Rep: 18,706 Quality: Low Completeness: 30%

All these require mut, how about let (a, b) = if .. else .. ?

March 10, 2026 Score: 1 Rep: 66,071 Quality: Low Completeness: 30%

I would instinctively follow this anyway since I would typically want to rename from thinga and thingb to thingmin and thingmax.

March 10, 2026 Score: 0 Rep: 15,666 Quality: Low Completeness: 30%

For completeness, let mut ab = [a, b]; ab.sort(); (ab[0], ab[1])

March 10, 2026 Score: 0 Rep: 11,519 Quality: Low Completeness: 40%

While I'm not as familiar with Rust, if there's an rust-esque way of writing (a, b) = (min(a, b), max(a, b)) it'd be the most clear imo. It looks like you effectively have that via a.min(b) and so on.

March 10, 2026 Score: 0 Rep: 18,706 Quality: Low Completeness: 60%

FWIW, there is nightly minimax that sorts pairs of values. Notably, it does the following:

pub const fn minmax(v1: T, v2: T) -> [T; 2] where T: [const] Ord, { if v2 < v1 { [v2, v1] } else { [v1, v2] } }
March 10, 2026 Score: 0 Rep: 43,706 Quality: Low Completeness: 40%

I'm not sure any language would have a single idiomatic philosophy at this level of specificity. That said, I personally find the first approach most readable. rustfmt will turn it into a single line, which I find very easy to read.