4141//! }
4242//! ```
4343
44- #[ cfg( feature = "tokio " ) ]
44+ #[ cfg( feature = "use_tokio " ) ]
4545extern crate futures;
4646#[ cfg( feature = "mio-evented" ) ]
4747extern crate mio;
4848extern crate nix;
49- #[ cfg( feature = "tokio " ) ]
50- extern crate tokio_core ;
49+ #[ cfg( feature = "use_tokio " ) ]
50+ extern crate tokio ;
5151
52- #[ cfg( feature = "tokio" ) ]
53- use futures:: { Async , Poll , Stream } ;
52+ use std:: fs;
53+ use std:: fs:: File ;
54+ use std:: io:: { self , SeekFrom } ;
55+ use std:: io:: prelude:: * ;
56+ use std:: os:: unix:: prelude:: * ;
57+ use std:: path:: Path ;
5458
59+ #[ cfg( feature = "use_tokio" ) ]
60+ use futures:: { Async , Poll , Stream } ;
5561#[ cfg( feature = "mio-evented" ) ]
5662use mio:: Evented ;
5763#[ cfg( feature = "mio-evented" ) ]
5864use mio:: unix:: EventedFd ;
59-
6065#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
6166use nix:: sys:: epoll:: * ;
6267use nix:: unistd:: close;
68+ #[ cfg( feature = "use_tokio" ) ]
69+ use tokio:: reactor:: { Handle , PollEvented } ;
6370
64- use std:: io:: prelude:: * ;
65- use std:: os:: unix:: prelude:: * ;
66- use std:: io:: { self , SeekFrom } ;
67- use std:: fs;
68- use std:: fs:: File ;
69- use std:: path:: Path ;
70-
71- #[ cfg( feature = "tokio" ) ]
72- use tokio_core:: reactor:: { Handle , PollEvented } ;
71+ pub use error:: Error ;
7372
7473mod error;
75- pub use error:: Error ;
7674
7775#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
7876pub struct Pin {
@@ -446,29 +444,57 @@ impl Pin {
446444
447445 /// Get a Stream of pin interrupts for this pin
448446 ///
449- /// The PinStream object can be used with the `tokio-core ` crate. You should probably call
447+ /// The PinStream object can be used with the `tokio` crate. You should probably call
450448 /// `set_edge()` before using this.
451449 ///
452- /// This method is only available when the `tokio` crate feature is enabled.
453- #[ cfg( feature = "tokio" ) ]
454- pub fn get_stream ( & self , handle : & Handle ) -> Result < PinStream > {
455- PinStream :: init ( self . clone ( ) , handle)
450+ /// This method is only available when the `use_tokio` crate feature is enabled.
451+ #[ cfg( feature = "use_tokio" ) ]
452+ pub fn get_stream_with_handle ( & self , handle : & Handle ) -> Result < PinStream > {
453+ PinStream :: init_with_handle ( self . clone ( ) , handle)
454+ }
455+
456+
457+ /// Get a Stream of pin interrupts for this pin
458+ ///
459+ /// The PinStream object can be used with the `tokio` crate. You should probably call
460+ /// `set_edge()` before using this.
461+ ///
462+ /// This method is only available when the `use_tokio` crate feature is enabled.
463+ #[ cfg( feature = "use_tokio" ) ]
464+ pub fn get_stream ( & self ) -> Result < PinStream > {
465+ PinStream :: init ( self . clone ( ) )
456466 }
457467
458468 /// Get a Stream of pin values for this pin
459469 ///
460- /// The PinStream object can be used with the `tokio-core ` crate. You should probably call
470+ /// The PinStream object can be used with the `tokio` crate. You should probably call
461471 /// `set_edge(Edge::BothEdges)` before using this.
462472 ///
463473 /// Note that the values produced are the value of the pin as soon as we get to handling the
464474 /// interrupt in userspace. Each time this stream produces a value, a change has occurred, but
465475 /// it could end up producing the same value multiple times if the value has changed back
466476 /// between when the interrupt occurred and when the value was read.
467477 ///
468- /// This method is only available when the `tokio` crate feature is enabled.
469- #[ cfg( feature = "tokio" ) ]
470- pub fn get_value_stream ( & self , handle : & Handle ) -> Result < PinValueStream > {
471- Ok ( PinValueStream ( PinStream :: init ( self . clone ( ) , handle) ?) )
478+ /// This method is only available when the `use_tokio` crate feature is enabled.
479+ #[ cfg( feature = "use_tokio" ) ]
480+ pub fn get_value_stream_with_handle ( & self , handle : & Handle ) -> Result < PinValueStream > {
481+ Ok ( PinValueStream ( PinStream :: init_with_handle ( self . clone ( ) , handle) ?) )
482+ }
483+
484+ /// Get a Stream of pin values for this pin
485+ ///
486+ /// The PinStream object can be used with the `tokio` crate. You should probably call
487+ /// `set_edge(Edge::BothEdges)` before using this.
488+ ///
489+ /// Note that the values produced are the value of the pin as soon as we get to handling the
490+ /// interrupt in userspace. Each time this stream produces a value, a change has occurred, but
491+ /// it could end up producing the same value multiple times if the value has changed back
492+ /// between when the interrupt occurred and when the value was read.
493+ ///
494+ /// This method is only available when the `use_tokio` crate feature is enabled.
495+ #[ cfg( feature = "use_tokio" ) ]
496+ pub fn get_value_stream ( & self ) -> Result < PinValueStream > {
497+ Ok ( PinValueStream ( PinStream :: init ( self . clone ( ) ) ?) )
472498 }
473499}
474500
@@ -538,7 +564,7 @@ impl PinPoller {
538564 /// making this call. This call makes use of epoll under the
539565 /// covers. To poll on multiple GPIOs or other event sources,
540566 /// poll asynchronously using the integration with either `mio`
541- /// or `tokio_core `.
567+ /// or `tokio `.
542568 ///
543569 /// This function will return Some(value) of the pin if a change is
544570 /// detected or None if a timeout occurs. Note that the value provided
@@ -613,23 +639,33 @@ impl Evented for AsyncPinPoller {
613639 }
614640}
615641
616- #[ cfg( feature = "tokio " ) ]
642+ #[ cfg( feature = "use_tokio " ) ]
617643pub struct PinStream {
618644 evented : PollEvented < AsyncPinPoller > ,
619645 skipped_first_event : bool ,
620646}
621647
622- #[ cfg( feature = "tokio " ) ]
648+ #[ cfg( feature = "use_tokio " ) ]
623649impl PinStream {
624- pub fn init ( pin : Pin , handle : & Handle ) -> Result < Self > {
650+ pub fn init_with_handle ( pin : Pin , handle : & Handle ) -> Result < Self > {
625651 Ok ( PinStream {
626652 evented : PollEvented :: new ( pin. get_async_poller ( ) ?, & handle) ?,
627653 skipped_first_event : false ,
628654 } )
629655 }
630656}
631657
632- #[ cfg( feature = "tokio" ) ]
658+ #[ cfg( feature = "use_tokio" ) ]
659+ impl PinStream {
660+ pub fn init ( pin : Pin ) -> Result < Self > {
661+ Ok ( PinStream {
662+ evented : PollEvented :: new ( pin. get_async_poller ( ) ?, & Handle :: default ( ) ) ?,
663+ skipped_first_event : false ,
664+ } )
665+ }
666+ }
667+
668+ #[ cfg( feature = "use_tokio" ) ]
633669impl Stream for PinStream {
634670 type Item = ( ) ;
635671 type Error = Error ;
@@ -650,18 +686,18 @@ impl Stream for PinStream {
650686 }
651687}
652688
653- #[ cfg( feature = "tokio " ) ]
689+ #[ cfg( feature = "use_tokio " ) ]
654690pub struct PinValueStream ( PinStream ) ;
655691
656- #[ cfg( feature = "tokio " ) ]
692+ #[ cfg( feature = "use_tokio " ) ]
657693impl PinValueStream {
658694 #[ inline]
659695 fn get_value ( & mut self ) -> Result < u8 > {
660696 get_value_from_file ( & mut self . 0 . evented . get_mut ( ) . devfile )
661697 }
662698}
663699
664- #[ cfg( feature = "tokio " ) ]
700+ #[ cfg( feature = "use_tokio " ) ]
665701impl Stream for PinValueStream {
666702 type Item = u8 ;
667703 type Error = Error ;
0 commit comments