feat: add Default impls and new() constructors#1211
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Default implementations and lightweight new() constructors across several backend-specific types, and standardizes enum defaults where appropriate (including a small behavioral fix in AudioWorklet device enumeration). These changes are platform conveniences (not trait-level guarantees) and primarily improve ergonomics for backend-specific usage.
Changes:
- Implement
Defaultfor core enums (BufferSize,SupportedBufferSize) and multiple backendHost/Devicetypes; addnew()constructors where idiomatic. - Adjust backend code to construct devices via
Device::new()/Device::default()consistently. - Fix AudioWorklet
Devices::default()to only enumerate whenHost::is_available().
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Adds Default for BufferSize and SupportedBufferSize with explicit default variants. |
| src/host/webaudio/mod.rs | Adds Default for Device/Host, adds Device::new(), and uses it in iteration/default device selection. |
| src/host/wasapi/mod.rs | Adds Default for WASAPI Host. |
| src/host/pipewire/device.rs | Changes Role default to Sink; adds Default for NodeOverrides and introduces NodeOverrides::new(). |
| src/host/null/mod.rs | Adds Default for several null-backend types and introduces new() constructors. |
| src/host/coreaudio/macos/mod.rs | Adds Default for CoreAudio (macOS) Host. |
| src/host/coreaudio/ios/mod.rs | Adds Default for iOS CoreAudio Device/Host and adds Device::new(). |
| src/host/coreaudio/ios/enumerate.rs | Updates enumeration/default-device construction to use Device::new() / Device::default(). |
| src/host/audioworklet/mod.rs | Adds Default for Device/Host, adds Device::new(), and fixes Devices::default() gating on availability. |
| src/host/asio/stream.rs | Derives Default for TimeBase and simplifies TimeBase::new() to delegate to default(). |
| src/host/aaudio/mod.rs | Adds Default for Host/Device, adds Device::new(), and updates fallback/default device creation. |
| src/host/aaudio/java_interface/definitions.rs | Adds Default to AudioDeviceType with Unknown as the default variant. |
| CHANGELOG.md | Documents the newly added Default/new() conveniences and the AudioWorklet enumeration fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
As I noticed PipeWire had a curious choice of
#[default]Roles, I did a sweep across all hosts to implementDefaultwhere it makes sense, add anew()constructor where idiomatic, and check the sanity of existingDefaultimplementations.These are not defined on the trait, so use it for platform-specific convenience rather than expecting it works cross-platform (it doesn't).
Additionally, tidy up the derives particularly on non-public types in order to reduce compile times.