use crate::{Buffer, Input, Node};
use core::fmt;
use core::ops::{Deref, DerefMut};
pub struct BoxedNode(pub Box<dyn Node>);
pub struct BoxedNodeSend(pub Box<dyn Node + Send>);
impl BoxedNode {
pub fn new<T>(node: T) -> Self
where
T: 'static + Node,
{
Self::from(Box::new(node))
}
}
impl BoxedNodeSend {
pub fn new<T>(node: T) -> Self
where
T: 'static + Node + Send,
{
Self::from(Box::new(node))
}
}
impl Node for BoxedNode {
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
self.0.process(inputs, output)
}
}
impl Node for BoxedNodeSend {
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
self.0.process(inputs, output)
}
}
impl<T> From<Box<T>> for BoxedNode
where
T: 'static + Node,
{
fn from(n: Box<T>) -> Self {
BoxedNode(n as Box<dyn Node>)
}
}
impl<T> From<Box<T>> for BoxedNodeSend
where
T: 'static + Node + Send,
{
fn from(n: Box<T>) -> Self {
BoxedNodeSend(n as Box<dyn Node + Send>)
}
}
impl Into<Box<dyn Node>> for BoxedNode {
fn into(self) -> Box<dyn Node> {
self.0
}
}
impl Into<Box<dyn Node + Send>> for BoxedNodeSend {
fn into(self) -> Box<dyn Node + Send> {
self.0
}
}
impl fmt::Debug for BoxedNode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BoxedNode").finish()
}
}
impl fmt::Debug for BoxedNodeSend {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("BoxedNodeSend").finish()
}
}
impl Deref for BoxedNode {
type Target = Box<dyn Node>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Deref for BoxedNodeSend {
type Target = Box<dyn Node + Send>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for BoxedNode {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl DerefMut for BoxedNodeSend {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}