Skip to content

Code tidying, particularly SampleFormat, with many functions as const - #1353

Open
Marco-Farruggio wants to merge 3 commits into
RustAudio:masterfrom
Marco-Farruggio:simplify-fill-equilibrium
Open

Code tidying, particularly SampleFormat, with many functions as const#1353
Marco-Farruggio wants to merge 3 commits into
RustAudio:masterfrom
Marco-Farruggio:simplify-fill-equilibrium

Conversation

@Marco-Farruggio

Copy link
Copy Markdown
Contributor
  1. Cleaned up a debug assertion in equilibrium.rs
  2. Made frames_to_duration a bit more legible
  3. Removed commented out i48/i48 lines
  4. Made a macro to implement SizedSample
  5. Made many methods on SampleFormat const

  1. Lined up match arms (I can undo this quickly if you'd like)

@LastExceed

LastExceed commented Sep 3, 2026

Copy link
Copy Markdown
Contributor
  1. replacing assert_eq!(x,y) with assert!(x == y) seems backwards to me. Isn't this the very thing assert_eq exists for?
  2. LGTM
  3. LGTM
  4. LGTM
  5. LGTM - particularly excited about this one, as I (kind of) needed it for new ASIO host implementation #1331 :D
  6. I too like lining things up, and I've been wondering if rust-fmt can be configured to allow this (as well as a few other things that I am currently too stubborn to fix in new ASIO host implementation #1331). But we should probably gather a few more opinions on this

PS: Try to record each change in a separate commit in the future. The enumeration you provided is the ideal degree of segmentation in my eyes. Probably not worth rewriting history retroactively here, as the PR is pretty easy to comprehend as-is, but as a general rule of thumb: "Commit early and often". You almost cannot overdo this

@Marco-Farruggio

Marco-Farruggio commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Yeah I personally like neat-looking code, and I can easily add back the _eq! if you'd like, I just removed it because when I thought the == was a bit cleaner, and sure, I'll stage it as separate commits going forward, thanks for the tip :)

Note on the branch name: I was originally going to clean up the fill_equilibrium function, alot more, but every time I refactored it I realised the original approach was good)

@Marco-Farruggio

Copy link
Copy Markdown
Contributor Author

Clippy shows 62 functions which could be const for me (I think some could be false positives), I see zero downside of making many of these const, but I spose making some of them const may come across as a false 'promise' that it will be const forever? For some methods it doesn't really even make sense, like SupportedStreamConfig::new, which would be runtime only. Things such as StreamInstant::new() though, I think should just be const as there's no reason for them not to be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants