pub use interface::Tick;
use interface::{Data, Read, TimerMarker, UniqueIdentifier, Update, Write};
use std::mem::take;
pub mod average;
pub mod fill;
pub mod foh;
pub mod fun;
pub mod gain;
#[cfg(feature = "gif")]
pub mod gif;
pub mod iir;
pub mod integrator;
pub mod leftright;
pub mod logging;
pub mod low_pass_filter;
pub mod multiplex;
pub mod once;
pub mod operator;
pub mod print;
pub mod pulse;
pub mod sampler;
pub mod select;
pub mod signals;
pub mod smooth;
pub mod timer;
pub struct Concat<T>(Vec<T>);
impl<T: Default> Default for Concat<T> {
fn default() -> Self {
Self(Vec::new())
}
}
impl<T> Update for Concat<T> where T: Send + Sync {}
impl<T, U> Read<U> for Concat<T>
where
T: Clone + Default + Send + Sync,
U: UniqueIdentifier<DataType = T>,
{
fn read(&mut self, data: Data<U>) {
self.0.push((*data).clone());
}
}
impl<T, U> Write<U> for Concat<T>
where
T: Clone + Send + Sync,
U: UniqueIdentifier<DataType = Vec<T>>,
{
fn write(&mut self) -> Option<Data<U>> {
Some(Data::new(take(&mut self.0)))
}
}
pub struct Source<T> {
n: usize,
data: Vec<T>,
}
impl<T> Source<T> {
pub fn new(data: Vec<T>, n: usize) -> Self {
Source { n, data }
}
}
impl<T> TimerMarker for Source<T> {}
impl<T> Update for Source<T> where T: Send + Sync {}
impl<T, V> Write<V> for Source<T>
where
V: UniqueIdentifier<DataType = Vec<T>>,
T: Send + Sync,
{
fn write(&mut self) -> Option<Data<V>> {
if self.data.is_empty() {
None
} else {
let y: Vec<T> = self.data.drain(..self.n).collect();
Some(Data::new(y))
}
}
}
pub trait Progress {
fn progress<S: Into<String>>(name: S, len: usize) -> Self;
fn increment(&mut self);
fn finish(&mut self) {}
}
impl Progress for indicatif::ProgressBar {
fn progress<S: Into<String>>(name: S, len: usize) -> Self {
let progress = indicatif::ProgressBar::new(len as u64);
progress.set_style(
indicatif::ProgressStyle::with_template(
"{msg} [{eta_precise}] {bar:50.cyan/blue} {percent:>3}%",
)
.unwrap(),
);
progress.set_message(name.into());
progress
}
#[inline]
fn increment(&mut self) {
self.inc(1)
}
#[inline]
fn finish(&mut self) {
Self::finish(self);
}
}