1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! [`Mdrv`] is a modular driver based on [`Mio`] for managing multiple connections over different protocols
//!
//! # Overview
//! 
//! The core of the [`Mdrv`] funtionality is the [`Driver`] structure.
//! In maintains an event loop which manages entities called proxies.
//! 
//! [`Proxy`] instances are passed to the driver to be inserted in event loop.
//! They can maintain different connections and reads and writes data over them.
//! 
//! Because of the proxy is moved to the driver we cannot directly access it.
//! The [`Handle`] is the way to communicate with the proxy by sending commands and receiving responces.
//! 
//! The pair of [`Handle`] and [`ProxyWrapper`] (the [`Proxy`] instance, that implements communication with the handle)
//! is usually constructed by [`create()`] function. 
//! This function takes user-defined structs that should implement [`UserProxy`] and [`UserHandle`] traits.
//! Also a command set should be defined for communication between proxy and handle.
//! These commands have to be able to convert from and into the basic [`Tx`] and [`Rx`] commands
//! by implementing [`From`] and [`Into`] traits.
//! 
//! The example dummy implementation of user structures could be found in [`dummy`] module.
//! 
//! # Simple example
//!
//! ```rust
//! use mdrv::{channel, driver, dummy};
//! 
//! // create driver instance
//! let mut driver = driver::Driver::new().unwrap();
//! // create dummy proxy and handle pair
//! let (proxy, mut handle) = dummy::create().unwrap();
//!
//! // We need a simple poll to wait for messages on handle
//! // A regular mio::Poll also can be used for that
//! let mut poll = channel::SinglePoll::new(&handle.rx).unwrap();
//! 
//! driver.attach(Box::new(proxy)).unwrap();
//!
//! // wait for one message from proxy to arrive
//! dummy::wait_msgs(&mut handle, &mut poll, 1).unwrap();
//! 
//! // read message received
//! match handle.user.msgs.pop_front().unwrap() {
//!     dummy::Rx::Attached => println!("attached to the driver"),
//!     other => panic!("{:?}", other),
//! }
//!
//! // now we don't need our proxy anymore
//! handle.close().unwrap(); // this also called on handle drop
//! 
//! // wait for proxy to be closed
//! dummy::wait_close(&mut handle, &mut poll).unwrap();
//! 
//! // read messages again
//! match handle.user.msgs.pop_front().unwrap() {
//!     dummy::Rx::Detached => println!("detached from the driver"),
//!     other => panic!("{:?}", other),
//! }
//! match handle.user.msgs.pop_front().unwrap() {
//!     dummy::Rx::Closed => println!("proxy has been dropped"),
//!     other => panic!("{:?}", other),
//! }
//! ```
//!
//! [`Mdrv`]: https://github.com/binp-automation/mdrv
//! [`Mio`]: https://github.com/carllerche/mio
//!
//! [`Driver`]: driver/struct.Driver.html
//! [`Proxy`]: proxy/trait.Proxy.html
//! [`Handle`]: proxy_handle/struct.Handle.html
//! [`ProxyWrapper`]: proxy_handle/struct.ProxyWrapper.html
//! [`create()`]: proxy_handle/fn.create.html
//! 
//! [`UserProxy`]: proxy_handle/trait.UserProxy.html
//! [`UserHandle`]: proxy_handle/trait.UserHandle.html
//! [`Tx`]: proxy_handle/enum.Tx.html
//! [`Rx`]: proxy_handle/enum.Rx.html
//! 
//! [`From`]: https://doc.rust-lang.org/nightly/core/convert/trait.From.html
//! [`Into`]: https://doc.rust-lang.org/nightly/core/convert/trait.Into.html
//! 
//! [`dummy`]: dummy/index.html
//! 

extern crate mio;
extern crate mio_extras;

pub mod error;
pub mod result;

pub mod channel;
pub mod proxy;
pub mod proxy_handle;
pub mod dummy;

mod event_loop;
pub mod driver;

pub use error::{Error};
pub use result::{Result};


#[cfg(test)]
#[macro_use]
extern crate matches;