Skip to content

Split Resampler into capability traits Adjustable and Resizable#132

Open
HEnquist wants to merge 1 commit into
next4.0from
capability-traits
Open

Split Resampler into capability traits Adjustable and Resizable#132
HEnquist wants to merge 1 commit into
next4.0from
capability-traits

Conversation

@HEnquist

Copy link
Copy Markdown
Owner

Builds on the next4.0 branch. Moves the capability-specific methods off the single Resampler trait into dedicated traits, turning two runtime errors into compile-time capabilities while keeping Resampler as the universal trait for mixed Box<dyn Resampler> collections.

Changes

  • New Adjustable<T>: Resampler<T>set_resample_ratio, set_resample_ratio_relative
  • New Resizable<T>: Resampler<T>set_chunk_size
  • Resampler::as_adjustable() / as_resizable() recover the capability from a trait object (default None; Async returns Some(self), Fft does not)
  • Removed the now-unreachable ResampleError::SyncNotAdjustable and ChunkSizeNotAdjustable variants

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and Resizable<T> (chunk size adjustment).
  • Added Resampler::as_adjustable() / as_resizable() to recover capabilities from &mut dyn Resampler<T> (default None; Async returns Some(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.
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