Split Resampler into capability traits Adjustable and Resizable#132
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the resampler API to model “can adjust resample ratio” and “can resize chunk size” as compile-time capabilities via dedicated traits, while keeping Resampler as the common trait for Box<dyn Resampler<_>> use cases.
Changes:
- Split capability-specific methods into new traits:
Adjustable<T>(ratio adjustment) andResizable<T>(chunk size adjustment). - Added
Resampler::as_adjustable()/as_resizable()to recover capabilities from&mut dyn Resampler<T>(defaultNone;AsyncreturnsSome(self)). - Removed the now-unreachable runtime error variants (
SyncNotAdjustable,ChunkSizeNotAdjustable) and updated docs/examples/tests accordingly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib.rs | Introduces Adjustable/Resizable traits, adds capability query methods on Resampler, and adds tests validating trait-object capability recovery. |
| src/asynchro.rs | Implements the new capability traits for Async and wires as_adjustable()/as_resizable() to return Some(self). |
| src/synchro.rs | Removes now-obsolete “not adjustable” ratio setters from the synchronous Fft resampler implementation. |
| src/error.rs | Removes obsolete error variants and updates documentation links to reference the new capability traits. |
| README.md | Documents the API change and shows updated usage patterns for concrete types vs dyn Resampler. |
| examples/polyfixedin_ramp64.rs | Updates imports to bring Adjustable into scope for ratio ramping calls. |
| examples/fixedout_ramp64.rs | Updates imports to bring Adjustable into scope for ratio ramping calls. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move the capability-specific methods off the Resampler trait: set_resample_ratio and set_resample_ratio_relative go to a new Adjustable trait, set_chunk_size to a new Resizable trait. Both extend Resampler. Resampler gains as_adjustable() and as_resizable() to recover the capabilities from a trait object, defaulting to None and overridden to Some(self) by Async. This turns the runtime SyncNotAdjustable / ChunkSizeNotAdjustable errors into compile-time capabilities, so both error variants are removed. Resampler stays the universal trait for mixed Box<dyn Resampler> collections. Update the examples and tests to bring the traits into scope, and document the change in the changelog and migration guide.
HEnquist
force-pushed
the
capability-traits
branch
from
June 23, 2026 21:56
88b4f46 to
d96f52d
Compare
… exact ratio bounds - Make `Resampler::as_adjustable`/`as_resizable` required rather than defaulting to `None`, so implementing `Adjustable`/`Resizable` and advertising it through a trait object cannot silently drift apart. `Fft` now declares both as `None` explicitly. - Add `Resampler::is_adjustable`/`is_resizable` so the capability can be queried through a shared `&dyn Resampler` without exclusive access. - Check the relative ratio directly in `set_resample_ratio_relative` instead of round-tripping through `(original * rel) / original`, which could round the exact bounds out of range and wrongly reject them. Adds a regression test. - Fix the stale `Async` doc that referenced `set_chunk_size()` without noting the `Resizable` trait. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The crate-level docs include README.md, so its headline example ran as a doctest. It uses `Fft`/`FixedSync`, which only exist with the default `fft_resampler` feature, so `cargo test --no-default-features` failed to compile it. Mark the block `ignore` (matching the other README snippets) and note the feature requirement. The Fft processing flow is still compile-tested by the `process_f64` example, which gates the import on the feature. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Builds on the
next4.0branch. Moves the capability-specific methods off the singleResamplertrait into dedicated traits, turning two runtime errors into compile-time capabilities while keepingResampleras the universal trait for mixedBox<dyn Resampler>collections.Changes
Adjustable<T>: Resampler<T>—set_resample_ratio,set_resample_ratio_relativeResizable<T>: Resampler<T>—set_chunk_sizeResampler::as_adjustable()/as_resizable()recover the capability from a trait object (defaultNone;AsyncreturnsSome(self),Fftdoes not)ResampleError::SyncNotAdjustableandChunkSizeNotAdjustablevariants