Skip to content
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

Add non-panicking variant of with_sample_rate #828

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

agausmann
Copy link
Contributor

When trying to select a configuration that is compatible with a specific sample rate, with_sample_rate gets a bit clunky because you have to implement the range checking yourself to avoid the panic.

The non-panicking try_with_sample_rate is much nicer in comparison.

Before:

device.supported_output_configs()?
    .filter_map(|cfg| if target_rate >= cfg.min_sample_rate() && target_rate <= cfg.max_sample_rate() {
        Some(cfg.with_sample_rate(target_rate))
    } else {
        None
    })

After:

device.supported_output_configs()?
    .filter_map(|cfg| cfg.try_with_sample_rate(target_rate))

@est31 est31 merged commit 4706396 into RustAudio:master Feb 5, 2024
14 of 16 checks passed
@agausmann agausmann deleted the try_with_sample_rate branch February 5, 2024 07:08
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