use std::cell::{Ref, RefMut}; use std::fmt; use std::ops::{Deref, DerefMut}; use actix_codec::{Decoder, Encoder}; use crate::sink::Sink; use crate::state::State; pub struct Item { state: State, sink: Sink<::Item>, item: ::Item, } impl Item where Codec: Encoder + Decoder, { pub(crate) fn new( state: State, sink: Sink<::Item>, item: ::Item, ) -> Self { Item { state, sink, item } } #[inline] pub fn state(&self) -> Ref { self.state.get_ref() } #[inline] pub fn state_mut(&mut self) -> RefMut { self.state.get_mut() } #[inline] pub fn sink(&self) -> &Sink<::Item> { &self.sink } #[inline] pub fn into_inner(self) -> ::Item { self.item } #[inline] pub fn into_parts( self, ) -> ( State, Sink<::Item>, ::Item, ) { (self.state, self.sink, self.item) } } impl Deref for Item where Codec: Encoder + Decoder, { type Target = ::Item; #[inline] fn deref(&self) -> &::Item { &self.item } } impl DerefMut for Item where Codec: Encoder + Decoder, { #[inline] fn deref_mut(&mut self) -> &mut ::Item { &mut self.item } } impl fmt::Debug for Item where Codec: Encoder + Decoder, ::Item: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_tuple("FramedItem").field(&self.item).finish() } }