improvements and cleanup

This commit is contained in:
Franz Heinzmann (Frando) 2021-02-19 18:51:09 +01:00
parent 091e6319cd
commit 7558fd3fe9
6 changed files with 107 additions and 127 deletions

View file

@ -1,10 +1,12 @@
use async_channel::{self, Receiver, Sender};
use async_std::prelude::*;
use async_std::task::{self, JoinHandle};
use rosc::{OscMessage, OscType};
use std::collections::{VecDeque};
use rosc::OscMessage;
use std::collections::VecDeque;
use thiserror::Error;
use crate::osc::{IntoOscArgs, OscMessageExt};
#[derive(Error, Debug)]
pub enum SwitcherError {
#[error("Channel for switcher events full")]
@ -205,76 +207,10 @@ impl Messages {
where
T: IntoOscArgs,
{
self.inner.push_back(osc_message(addr, args));
self.inner.push_back(OscMessage::new(addr, args));
}
fn pop(&mut self) -> Option<OscMessage> {
self.inner.pop_front()
}
}
fn osc_message<T>(addr: impl ToString, args: T) -> OscMessage
where
T: IntoOscArgs,
{
// let args: Vec<OscType> = args.into_iter().map(|a| a.into()).collect();
let args = args.into_osc_args();
let addr = addr.to_string();
OscMessage { addr, args }
}
pub trait IntoOscArgs {
fn into_osc_args(self) -> Vec<OscType>;
}
impl<T> IntoOscArgs for Vec<T>
where
T: Into<OscType>,
{
fn into_osc_args(self) -> Vec<OscType> {
let args: Vec<OscType> = self.into_iter().map(|a| a.into()).collect();
args
}
}
impl<T1> IntoOscArgs for (T1,)
where
T1: Into<OscType>,
{
fn into_osc_args(self) -> Vec<OscType> {
vec![self.0.into()]
}
}
impl<T1, T2> IntoOscArgs for (T1, T2)
where
T1: Into<OscType>,
T2: Into<OscType>,
{
fn into_osc_args(self) -> Vec<OscType> {
vec![self.0.into(), self.1.into()]
}
}
impl<T1, T2, T3> IntoOscArgs for (T1, T2, T3)
where
T1: Into<OscType>,
T2: Into<OscType>,
T3: Into<OscType>,
{
fn into_osc_args(self) -> Vec<OscType> {
vec![self.0.into(), self.1.into(), self.2.into()]
}
}
impl IntoOscArgs for OscType {
fn into_osc_args(self) -> Vec<OscType> {
vec![self]
}
}
// impl IntoOscArgs for Vec<OscType> {
// fn into_osc_args(self) -> Vec<OscType> {
// self
// }
// }