To (try and) answer the question nonetheless, here are some local refactorings I could come up with.
E.g.: you could replace the whole take+transform+set logic with one that only does the state transformations when they actually change something. This way the relevant section of code could look e.g. like
match &mut self.state {
ProcessHandlerState::Idle => {
out_port.fill(0.0);
}
ProcessHandlerState::Measurement(producer) => {
let in_port = self.in_port.as_slice(process_scope);
producer.recording_prod.push_slice(in_port);
let mut write_signal = |signal: &mut PopIter<'_, HeapCons<f32>>| {
let mut buf_empty = false;
for o in out_port.iter_mut() {
if let Some(s) = signal.next() {
*o = s * self.amplitued;
} else {
*o = 0.0;
buf_empty = true;
}
}
buf_empty
};
let stop = match &mut producer.pop_iter() {
measurement::PopState::Some(signal) => {
write_signal(signal);
false
}
measurement::PopState::Exhausted(signal) => {
let buf_empty = write_signal(signal);
buf_empty
}
measurement::PopState::ConsumerDropped => {
out_port.fill(0.0);
true
}
};
if stop {
self.state = ProcessHandlerState::Idle;
}
}
};
(this behaves different on panics, not setting the state to Idle then)
I'm also noticing that the measurement::PopState::Some and measurement::PopState::Exhausted variants are containing the same kind of field, produced the exact same way, and processed the exact same way. This might be more nice to work with as a tuple (Flag, PopIter) rather than two separate Flag1(PopIter), Flag2(PopIter) variants..
pub enum PopState<'a> {
Some(PopStateFlag, PopIter<'a, HeapCons<f32>>),
ConsumerDropped,
}
pub enum PopStateFlag {
NonExhausted,
Exhausted,
}
impl Producer {
pub fn pop_iter(&mut self) -> PopState {
if self.state.consumer_dropped.load(atomic::Ordering::Acquire) {
PopState::ConsumerDropped
} else {
let flag = if self.state.signal_exhausted.load(atomic::Ordering::Acquire) {
PopStateFlag::Exhausted
} else {
PopStateFlag::NonExhausted
};
PopState::Some(flag, self.signal_cons.pop_iter())
}
}
}
and
match &mut self.state {
ProcessHandlerState::Idle => {
out_port.fill(0.0);
}
ProcessHandlerState::Measurement(producer) => {
let in_port = self.in_port.as_slice(process_scope);
producer.recording_prod.push_slice(in_port);
let mut write_signal = |signal: &mut PopIter<'_, HeapCons<f32>>| {
let mut buf_empty = false;
for o in out_port.iter_mut() {
if let Some(s) = signal.next() {
*o = s * self.amplitued;
} else {
*o = 0.0;
buf_empty = true;
}
}
buf_empty
};
let stop = match &mut producer.pop_iter() {
measurement::PopState::Some(flag, signal) => {
write_signal(signal) && matches!(flag, PopStateFlag::Exhausted)
}
measurement::PopState::ConsumerDropped => {
out_port.fill(0.0);
true
}
};
if stop {
self.state = ProcessHandlerState::Idle;
}
}
};
Then you can even inline the write_signal logic again because of the deduplication 
The same kind of deduplication (but perhaps less nicely) without changing the enum could have also been achieved with an or-pattern, I presume 
Anyway.. deduplicated:
match &mut self.state {
ProcessHandlerState::Idle => {
out_port.fill(0.0);
}
ProcessHandlerState::Measurement(producer) => {
let in_port = self.in_port.as_slice(process_scope);
producer.recording_prod.push_slice(in_port);
let stop = match &mut producer.pop_iter() {
measurement::PopState::Some(flag, signal) => {
let mut buf_empty = false;
for o in out_port.iter_mut() {
if let Some(s) = signal.next() {
*o = s * self.amplitued;
} else {
*o = 0.0;
buf_empty = true;
}
}
buf_empty && matches!(flag, PopStateFlag::Exhausted)
}
measurement::PopState::ConsumerDropped => {
out_port.fill(0.0);
true
}
};
if stop {
self.state = ProcessHandlerState::Idle;
}
}
};
While I'm at it, looking at
measurement::PopState::Some(flag, signal) => {
let mut buf_empty = false;
for o in out_port.iter_mut() {
if let Some(s) = signal.next() {
*o = s * self.amplitued;
} else {
*o = 0.0;
buf_empty = true;
}
}
buf_empty && matches!(flag, PopStateFlag::Exhausted)
}
which works with signal: impl ExactSizeIterator, you could also turn the empty-ness check into a simple case of:
measurement::PopState::Some(flag, signal) => {
for o in out_port.iter_mut() {
if let Some(s) = signal.next() {
*o = s * self.amplitued;
} else {
*o = 0.0;
}
}
signal.len() == 0 && matches!(flag, PopStateFlag::Exhausted)
}
which then presents itself for further rewriting e.g. pulling out the *o =
measurement::PopState::Some(flag, signal) => {
for o in out_port.iter_mut() {
*o = if let Some(s) = signal.next() {
s * self.amplitued
} else {
0.0
};
}
signal.len() == 0 && matches!(flag, PopStateFlag::Exhausted)
}
then using some Option combinators
measurement::PopState::Some(flag, signal) => {
for o in out_port.iter_mut() {
*o = signal.next().map_or(0.0, |s| s * self.amplitued);
}
signal.len() == 0 && matches!(flag, PopStateFlag::Exhausted)
}
and then a neat slice-method:
measurement::PopState::Some(flag, signal) => {
out_port.fill_with(|| signal.next().map_or(0.0, |s| s * self.amplitued));
signal.len() == 0 && matches!(flag, PopStateFlag::Exhausted)
}
By the way, while looking through the code, I've found 2 issues with this code
pub fn update_from_iter<I>(&mut self, iter: I) -> bool
where
I: IntoIterator<Item = f32>,
{
let mut new_peak = false;
for s in iter {
new_peak = new_peak || self.update(s);
}
new_peak
}
pub fn update(&mut self, sample: f32) -> bool {
let sample_squared = sample * sample;
self.square_sum += sample_squared;
let mut new_peak = false;
if self.peak < sample {
self.peak = sample;
new_peak = true;
}
let removed = self.buf.push_overwrite(sample_squared);
if let Some(r) = removed {
self.square_sum -= r;
}
new_peak
}
new_peak = new_peak || self.update(s)'s behavior when || short-circuits seems to be wrong and/or unintended
- handling floating-point values the way they are handled with the (repeated) use of
self.square_sum += … and then (later) self.square_sum -= … could result in the running sum value (slowly) drifting away over time, becoming further and further removed from the actual current squared sum of all values in buf