use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use parking_lot::Mutex;
use crate::consumers::consumer_once::BoxConsumerOnce;
use crate::consumers::macros::{
impl_box_conditional_consumer,
impl_box_consumer_methods,
impl_conditional_consumer_clone,
impl_conditional_consumer_conversions,
impl_conditional_consumer_debug_display,
impl_consumer_clone,
impl_consumer_common_methods,
impl_consumer_debug_display,
impl_shared_conditional_consumer,
impl_shared_consumer_methods,
};
use crate::macros::{
impl_arc_conversions,
impl_box_conversions,
impl_closure_trait,
impl_rc_conversions,
};
use crate::predicates::predicate::{
ArcPredicate,
BoxPredicate,
Predicate,
RcPredicate,
};
mod box_stateful_consumer;
pub use box_stateful_consumer::BoxStatefulConsumer;
mod rc_stateful_consumer;
pub use rc_stateful_consumer::RcStatefulConsumer;
mod arc_stateful_consumer;
pub use arc_stateful_consumer::ArcStatefulConsumer;
mod fn_stateful_consumer_ops;
pub use fn_stateful_consumer_ops::FnStatefulConsumerOps;
mod box_conditional_stateful_consumer;
pub use box_conditional_stateful_consumer::BoxConditionalStatefulConsumer;
mod arc_conditional_stateful_consumer;
pub use arc_conditional_stateful_consumer::ArcConditionalStatefulConsumer;
mod rc_conditional_stateful_consumer;
pub use rc_conditional_stateful_consumer::RcConditionalStatefulConsumer;
pub trait StatefulConsumer<T> {
fn accept(&mut self, value: &T);
fn into_box(self) -> BoxStatefulConsumer<T>
where
Self: Sized + 'static,
{
let mut consumer = self;
BoxStatefulConsumer::new(move |t| consumer.accept(t))
}
fn into_rc(self) -> RcStatefulConsumer<T>
where
Self: Sized + 'static,
{
let mut consumer = self;
RcStatefulConsumer::new(move |t| consumer.accept(t))
}
fn into_arc(self) -> ArcStatefulConsumer<T>
where
Self: Sized + Send + 'static,
{
let mut consumer = self;
ArcStatefulConsumer::new(move |t| consumer.accept(t))
}
fn into_fn(self) -> impl FnMut(&T)
where
Self: Sized + 'static,
{
let mut consumer = self;
move |t| consumer.accept(t)
}
fn into_once(self) -> BoxConsumerOnce<T>
where
Self: Sized + 'static,
{
BoxConsumerOnce::new(move |t| {
let mut consumer = self;
consumer.accept(t);
})
}
fn to_box(&self) -> BoxStatefulConsumer<T>
where
Self: Sized + Clone + 'static,
{
self.clone().into_box()
}
fn to_rc(&self) -> RcStatefulConsumer<T>
where
Self: Sized + Clone + 'static,
{
self.clone().into_rc()
}
fn to_arc(&self) -> ArcStatefulConsumer<T>
where
Self: Sized + Clone + Send + 'static,
{
self.clone().into_arc()
}
fn to_fn(&self) -> impl FnMut(&T)
where
Self: Sized + Clone + 'static,
{
self.clone().into_fn()
}
fn to_once(&self) -> BoxConsumerOnce<T>
where
Self: Clone + 'static,
{
self.clone().into_once()
}
}