-
Notifications
You must be signed in to change notification settings - Fork 543
Code tidying, particularly SampleFormat, with many functions as const #1353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
roderickvd
merged 11 commits into
RustAudio:master
from
Marco-Farruggio:simplify-fill-equilibrium
Sep 20, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
af5cd8d
general clean ups, particularly sample formats, with const for many f…
Marco-Farruggio beabb8d
undid the match arm lining-up, so that code quality is happy
Marco-Farruggio 9f37da8
submitted to rust-fmt
Marco-Farruggio 3c92ecf
make frames_to_duration const
Marco-Farruggio 56e5d84
use {text} in format strings, where logical
Marco-Farruggio dd12fa3
timestamp creation fns now const
Marco-Farruggio 6b74655
reverted debug assertion formatting in equilibrium.rs
Marco-Farruggio 8a57323
fixed layout nitpicks
Marco-Farruggio 8800fb5
updated changelog and upgrading docs
Marco-Farruggio 27980f8
nitpick cleanse, added entry to numbered list at the top of upgrading.md
Marco-Farruggio 38117f8
cleaned up a doc comment, as i believe... that rust,ignore works just…
Marco-Farruggio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ This guide covers breaking changes requiring code updates. See [CHANGELOG.md](CH | |
| - [ ] Replace `InputCallbackInfo`/`OutputCallbackInfo` with `CallbackInfo`. | ||
| - [ ] Replace `InputStreamTimestamp`/`OutputStreamTimestamp` with `StreamTimestamp`; `capture`/`playback` is now `device`. | ||
| - [ ] Remove `ErrorKind::Xrun` match arms; read `CallbackInfo::xrun()` instead. | ||
| - [ ] Update `SampleFormat` method calls to use `self` instead of `&self`; methods are now `const`. | ||
|
|
||
| ## 1. `DeviceTrait` and `StreamTrait` require `Send + Sync` | ||
|
|
||
|
|
@@ -92,6 +93,29 @@ Ordering of `xrun()` relative to the glitch it reports varies by host; see [`Cal | |
|
|
||
| [`CallbackInfo::xrun()`]: https://docs.rs/cpal/latest/cpal/struct.CallbackInfo.html#method.xrun | ||
|
|
||
| ## 5. `SampleFormat` methods made `const`, and take `self` | ||
|
|
||
| **What changed:** `SampleFormat` methods are now constant, and don't take a reference anymore. | ||
|
|
||
| ```rust | ||
| // Before (v0.18): | ||
| let i16_is_int: bool = SampleFormat::I16.is_int(); | ||
|
|
||
| let mut formats = vec![SampleFormat::I16, SampleFormat::F32]; | ||
| formats.retain(SampleFormat::is_int); | ||
|
|
||
| // After (v0.19): constant, and not referenced | ||
| const I16_IS_INT: bool = SampleFormat::I16.is_int(); | ||
|
|
||
| let mut formats = vec![SampleFormat::I16, SampleFormat::F32]; | ||
| formats.retain(|f| f.is_int()); | ||
| ``` | ||
|
|
||
| **Impact:** `SampleFormat` can now be used in a `const` environment. | ||
|
|
||
| **Why:** `SampleFormat` is a simple enum, there was no reason why it shouldn't be const-friendly, and since every method was both `inline` and it implements `Copy`, there is no performance downside to it taking `self`, but simply more legible than dereferencing. | ||
|
|
||
| [`SampleFormat`]: https://docs.rs/cpal/latest/cpal/enum.SampleFormat.html | ||
| --- | ||
|
|
||
| # Upgrading from v0.17 to v0.18 | ||
|
|
@@ -406,13 +430,13 @@ let device = host.device_by_id(&id); | |
|
|
||
| ```rust | ||
| // Before (v0.17) | ||
| for line in desc.extended() { // &[String] | ||
| println!("{}", line); // line: &String | ||
| for line in desc.extended() { // &[String] | ||
| println!("{line}"); // line: &String | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spacing of the comment seems unaligned with the one above it. |
||
| } | ||
|
|
||
| // After (v0.18) | ||
| for line in desc.extended() { // impl Iterator<Item = &str> | ||
| println!("{}", line); // line: &str — Display, write!, format! all unchanged | ||
| for line in desc.extended() { // impl Iterator<Item = &str> | ||
| println!("{line}"); // line: &str — Display, write!, format! all unchanged | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -540,7 +564,7 @@ let name = device.name()?; | |
|
|
||
| // New: For user-facing display | ||
| let desc = device.description()?; | ||
| println!("Device: {}", desc); // or desc.name() for just the name | ||
| println!("Device: {desc}"); // or desc.name() for just the name | ||
|
|
||
| // New: For stable identification and persistence | ||
| let id = device.id()?; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, this should also have an entry in the numbered list at the top.