use bevy_ecs::prelude::Entity;
use std::{cell::RefCell, rc::Rc};
use smallvec::SmallVec;
pub struct StreamBuffer<T> {
pub(crate) container: Rc<RefCell<DefaultStreamBufferContainer<T>>>,
pub(crate) target: Option<Entity>,
}
impl<Container> Clone for StreamBuffer<Container> {
fn clone(&self) -> Self {
Self {
container: Rc::clone(&self.container),
target: self.target,
}
}
}
impl<T> StreamBuffer<T> {
pub fn send(&self, input: T) {
self.container.borrow_mut().push(input);
}
pub fn target(&self) -> Option<Entity> {
self.target
}
}
pub type DefaultStreamBufferContainer<T> = SmallVec<[T; 16]>;