41
41
//! }
42
42
//! ```
43
43
44
- #[ cfg( feature = "tokio " ) ]
44
+ #[ cfg( feature = "use_tokio " ) ]
45
45
extern crate futures;
46
46
#[ cfg( feature = "mio-evented" ) ]
47
47
extern crate mio;
48
48
extern crate nix;
49
- #[ cfg( feature = "tokio " ) ]
50
- extern crate tokio_core ;
49
+ #[ cfg( feature = "use_tokio " ) ]
50
+ extern crate tokio ;
51
51
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 ;
54
58
59
+ #[ cfg( feature = "use_tokio" ) ]
60
+ use futures:: { Async , Poll , Stream } ;
55
61
#[ cfg( feature = "mio-evented" ) ]
56
62
use mio:: Evented ;
57
63
#[ cfg( feature = "mio-evented" ) ]
58
64
use mio:: unix:: EventedFd ;
59
-
60
65
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
61
66
use nix:: sys:: epoll:: * ;
62
67
use nix:: unistd:: close;
68
+ #[ cfg( feature = "use_tokio" ) ]
69
+ use tokio:: reactor:: { Handle , PollEvented } ;
63
70
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 ;
73
72
74
73
mod error;
75
- pub use error:: Error ;
76
74
77
75
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
78
76
pub struct Pin {
@@ -446,29 +444,57 @@ impl Pin {
446
444
447
445
/// Get a Stream of pin interrupts for this pin
448
446
///
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
450
448
/// `set_edge()` before using this.
451
449
///
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 ( ) )
456
466
}
457
467
458
468
/// Get a Stream of pin values for this pin
459
469
///
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
461
471
/// `set_edge(Edge::BothEdges)` before using this.
462
472
///
463
473
/// Note that the values produced are the value of the pin as soon as we get to handling the
464
474
/// interrupt in userspace. Each time this stream produces a value, a change has occurred, but
465
475
/// it could end up producing the same value multiple times if the value has changed back
466
476
/// between when the interrupt occurred and when the value was read.
467
477
///
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 ( ) ) ?) )
472
498
}
473
499
}
474
500
@@ -538,7 +564,7 @@ impl PinPoller {
538
564
/// making this call. This call makes use of epoll under the
539
565
/// covers. To poll on multiple GPIOs or other event sources,
540
566
/// poll asynchronously using the integration with either `mio`
541
- /// or `tokio_core `.
567
+ /// or `tokio `.
542
568
///
543
569
/// This function will return Some(value) of the pin if a change is
544
570
/// detected or None if a timeout occurs. Note that the value provided
@@ -613,23 +639,33 @@ impl Evented for AsyncPinPoller {
613
639
}
614
640
}
615
641
616
- #[ cfg( feature = "tokio " ) ]
642
+ #[ cfg( feature = "use_tokio " ) ]
617
643
pub struct PinStream {
618
644
evented : PollEvented < AsyncPinPoller > ,
619
645
skipped_first_event : bool ,
620
646
}
621
647
622
- #[ cfg( feature = "tokio " ) ]
648
+ #[ cfg( feature = "use_tokio " ) ]
623
649
impl PinStream {
624
- pub fn init ( pin : Pin , handle : & Handle ) -> Result < Self > {
650
+ pub fn init_with_handle ( pin : Pin , handle : & Handle ) -> Result < Self > {
625
651
Ok ( PinStream {
626
652
evented : PollEvented :: new ( pin. get_async_poller ( ) ?, & handle) ?,
627
653
skipped_first_event : false ,
628
654
} )
629
655
}
630
656
}
631
657
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" ) ]
633
669
impl Stream for PinStream {
634
670
type Item = ( ) ;
635
671
type Error = Error ;
@@ -650,18 +686,18 @@ impl Stream for PinStream {
650
686
}
651
687
}
652
688
653
- #[ cfg( feature = "tokio " ) ]
689
+ #[ cfg( feature = "use_tokio " ) ]
654
690
pub struct PinValueStream ( PinStream ) ;
655
691
656
- #[ cfg( feature = "tokio " ) ]
692
+ #[ cfg( feature = "use_tokio " ) ]
657
693
impl PinValueStream {
658
694
#[ inline]
659
695
fn get_value ( & mut self ) -> Result < u8 > {
660
696
get_value_from_file ( & mut self . 0 . evented . get_mut ( ) . devfile )
661
697
}
662
698
}
663
699
664
- #[ cfg( feature = "tokio " ) ]
700
+ #[ cfg( feature = "use_tokio " ) ]
665
701
impl Stream for PinValueStream {
666
702
type Item = u8 ;
667
703
type Error = Error ;
0 commit comments