#![allow(deprecated)]
use super::{caching::Caching, direct::Obs, traits::Wrap};
#[cfg(feature = "std")]
use crate::traits::Consumer;
use crate::{
rb::RbRef,
traits::{
Based,
consumer::{DelegateConsumer, impl_consumer_traits},
observer::DelegateObserver,
producer::{DelegateProducer, Producer, impl_producer_traits},
},
};
#[deprecated(note = "use Caching directly; frozen endpoints now publish changes immediately and will be removed in the next breaking release")]
pub struct Frozen<R: RbRef, const P: bool, const C: bool> {
inner: Caching<R, P, C>,
}
#[deprecated(note = "use CachingProd; writes are now published immediately")]
pub type FrozenProd<R> = Frozen<R, true, false>;
#[deprecated(note = "use CachingCons; removals are now published immediately")]
pub type FrozenCons<R> = Frozen<R, false, true>;
impl<R: RbRef, const P: bool, const C: bool> Frozen<R, P, C> {
pub fn new(rb: R) -> Self {
Self::from_caching(Caching::new(rb))
}
pub(crate) fn from_caching(inner: Caching<R, P, C>) -> Self {
Self { inner }
}
pub fn observe(&self) -> Obs<R> {
self.inner.observe()
}
#[deprecated(note = "changes are published immediately; remove this call")]
pub fn commit(&self) {}
#[deprecated(note = "the caching endpoint fetches progress automatically; remove this call")]
pub fn fetch(&self) {
self.inner.fetch();
}
#[deprecated(note = "changes are published immediately and progress is fetched automatically; remove this call")]
pub fn sync(&self) {
self.inner.fetch();
}
}
impl<R: RbRef> FrozenProd<R> {
#[deprecated(
note = "discard is now a no-op because writes are immediately published; stage items outside the ring buffer to support rollback"
)]
pub fn discard(&mut self) {}
}
impl<R: RbRef, const P: bool, const C: bool> Based for Frozen<R, P, C> {
type Base = Caching<R, P, C>;
fn base(&self) -> &Self::Base {
&self.inner
}
fn base_mut(&mut self) -> &mut Self::Base {
&mut self.inner
}
}
impl<R: RbRef, const P: bool, const C: bool> Wrap for Frozen<R, P, C> {
type RbRef = R;
fn rb_ref(&self) -> &R {
self.inner.rb_ref()
}
fn into_rb_ref(self) -> R {
self.inner.into_rb_ref()
}
}
impl<R: RbRef, const P: bool, const C: bool> AsRef<Self> for Frozen<R, P, C> {
fn as_ref(&self) -> &Self {
self
}
}
impl<R: RbRef, const P: bool, const C: bool> AsMut<Self> for Frozen<R, P, C> {
fn as_mut(&mut self) -> &mut Self {
self
}
}
impl<R: RbRef, const P: bool, const C: bool> DelegateObserver for Frozen<R, P, C> {}
impl<R: RbRef> DelegateProducer for FrozenProd<R> {}
impl<R: RbRef> DelegateConsumer for FrozenCons<R> {}
impl_producer_traits!(FrozenProd<R: RbRef>);
impl_consumer_traits!(FrozenCons<R: RbRef>);