Skip to content

Commit

Permalink
Actually, we don't need pin_project
Browse files Browse the repository at this point in the history
  • Loading branch information
najamelan committed Sep 24, 2019
1 parent 892fd0f commit db85733
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 49 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ status = "actively-developed"
repository = "najamelan/pharos"

[dependencies]
pin-project = "^0.4.0-beta"

[dependencies.futures-preview]
features = ["async-await", "nightly"]
version = "^0.3.0-alpha"
Expand Down
1 change: 0 additions & 1 deletion Cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ badges:
dependencies:

futures-preview : { version: ^0.3.0-alpha, features: [async-await, nightly] }
pin-project : ^0.4.0-beta

68 changes: 23 additions & 45 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ impl<Event> Stream for Events<Event> where Event: Clone + 'static + Send
/// The sender of the channel.
/// For pharos 0.3.0 on x64 Linux: `std::mem::size_of::<Sender<_>>() == 56`
//
#[ pin_project ]
//
pub(crate) enum Sender<Event> where Event: Clone + 'static + Send
{
Bounded { #[pin] tx: FutSender<Event> , filter: Option<Filter<Event>> } ,
Unbounded{ #[pin] tx: FutUnboundedSender<Event>, filter: Option<Filter<Event>> } ,
Bounded { tx: FutSender<Event> , filter: Option<Filter<Event>> } ,
Unbounded{ tx: FutUnboundedSender<Event>, filter: Option<Filter<Event>> } ,
}


Expand Down Expand Up @@ -144,12 +142,10 @@ impl<Event> Sender<Event> where Event: Clone + 'static + Send

/// The receiver of the channel.
//
#[ pin_project ]
//
enum Receiver<Event> where Event: Clone + 'static + Send
{
Bounded { #[pin] rx: FutReceiver<Event> } ,
Unbounded{ #[pin] rx: FutUnboundedReceiver<Event> } ,
Bounded { rx: FutReceiver<Event> } ,
Unbounded{ rx: FutUnboundedReceiver<Event> } ,
}


Expand Down Expand Up @@ -186,16 +182,12 @@ impl<Event> Stream for Receiver<Event> where Event: Clone + 'static + Send
{
type Item = Event;

#[ project ]
//
fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll< Option<Self::Item> >
{
#[ project ]
//
match self.project()
match self.get_mut()
{
Receiver::Bounded { rx } => rx.poll_next( cx ),
Receiver::Unbounded{ rx } => rx.poll_next( cx ),
Receiver::Bounded { rx } => Pin::new( rx ).poll_next( cx ),
Receiver::Unbounded{ rx } => Pin::new( rx ).poll_next( cx ),
}
}
}
Expand All @@ -206,57 +198,43 @@ impl<Event> Sink<Event> for Sender<Event> where Event: Clone + 'static + Send
{
type Error = Error;

#[ project ]
//

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
{
#[ project ]
//
match self.project()
match self.get_mut()
{
Sender::Bounded { tx, .. } => tx.poll_ready( cx ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => tx.poll_ready( cx ).map_err( Into::into ),
Sender::Bounded { tx, .. } => Pin::new( tx ).poll_ready( cx ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => Pin::new( tx ).poll_ready( cx ).map_err( Into::into ),
}
}

#[ project ]
//

fn start_send( self: Pin<&mut Self>, item: Event ) -> Result<(), Self::Error>
{
#[ project ]
//
match self.project()
match self.get_mut()
{
Sender::Bounded { tx, .. } => tx.start_send( item ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => tx.start_send( item ).map_err( Into::into ),
Sender::Bounded { tx, .. } => Pin::new( tx ).start_send( item ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => Pin::new( tx ).start_send( item ).map_err( Into::into ),
}
}

/// This will do a send under the hood, so the same errors as from start_send can occur here.
//
#[ project ]
//

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
{
#[ project ]
//
match self.project()
match self.get_mut()
{
Sender::Bounded { tx, .. } => tx.poll_flush( cx ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => tx.poll_flush( cx ).map_err( Into::into ),
Sender::Bounded { tx, .. } => Pin::new( tx ).poll_flush( cx ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => Pin::new( tx ).poll_flush( cx ).map_err( Into::into ),
}
}

#[ project ]
//

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>
{
#[ project ]
//
match self.project()
match self.get_mut()
{
Sender::Bounded { tx, .. } => tx.poll_close( cx ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => tx.poll_close( cx ).map_err( Into::into ),
Sender::Bounded { tx, .. } => Pin::new( tx ).poll_close( cx ).map_err( Into::into ),
Sender::Unbounded{ tx, .. } => Pin::new( tx ).poll_close( cx ).map_err( Into::into ),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ mod import
{
std :: { fmt, error::Error as ErrorTrait, ops::Deref, any::type_name } ,
std :: { task::{ Poll, Context }, pin::Pin } ,
pin_project :: { project, pin_project } ,

futures ::
{
Expand Down

0 comments on commit db85733

Please sign in to comment.